Skip to content
Snippets Groups Projects
Commit 37d5c3eb authored by Brutzman, Don's avatar Brutzman, Don
Browse files

Homework 1 submission with refactor/rename to have student name first

parent 2ccd6b17
No related branches found
No related tags found
No related merge requests found
//package Assignment01;
import java.io.*;
import java.net.*;
/**
*
* @author Jeremiah Sasala
*/
public class SasalaClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
while(true){
try
{
System.out.println("-------------------------------------------------------------------");
// from the server, instead of one only.
Socket socket = new Socket("127.0.0.1", 2317);
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String serverMessage01 = br.readLine();
String serverMessage02 = br.readLine();
String serverMessage03 = br.readLine();
String serverMessage04 = br.readLine();
String serverMessage05 = br.readLine();
System.out.println("The message the server sent was . . . " + serverMessage01);
System.out.println("The message the server sent was . . . " + serverMessage02);
System.out.println("The message the server sent was . . . " + serverMessage03);
System.out.println("The message the server sent was . . . " + serverMessage04);
System.out.println("The message the server sent was . . . " + serverMessage05);
}
catch(Exception e)
{
System.out.println("Problem with client");
System.out.println(e);
}
}
}
}
File added
//package Assignment01;
import java.io.*;
import java.net.*;
/**
*
* @author Jeremiah Sasala
*/
public class SasalaServer {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try
{
ServerSocket serverSocket = new ServerSocket(2317);
while(true)
{
Socket clientConnection = serverSocket.accept();
OutputStream os = clientConnection.getOutputStream();
PrintStream ps = new PrintStream(os);
String entityName = "Ranger";
double xPos = Math.round(Math.random()*10);
double yPos = Math.round(Math.random()*10);
double zPos = Math.round(Math.random()*10);
ps.println("Entity position information");
ps.println("Name: " + entityName);
ps.println("X coordinate: " + xPos);
ps.println("Y coordinate: " + yPos);
ps.println("Z coordinate: " + zPos);
InetAddress localAddress = clientConnection.getLocalAddress();
InetAddress remoteAddress = clientConnection.getInetAddress();
int localPort = clientConnection.getLocalPort();
int remotePort = clientConnection.getPort();
System.out.println("Socket pair: (( " + localAddress.toString() + ", " + localPort + " ), ( " +
remoteAddress.toString() + ", " + remotePort + " ))");
ps.flush();
clientConnection.close();
}
}
catch(Exception e)
{
System.out.println("problem with networking: " + e);
}
}
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment