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

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

parent 37d5c3eb
No related branches found
No related tags found
No related merge requests found
projects/Assignments/homework1/SnellConsoleOutput.png

176 KiB

File added
//package PositionClient;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
/**
*
* @author AJSNELL
*/
public class SnellPositionClient {
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
String hostName = args[0];
try (Socket clientSocket = new Socket(hostName, 8005);
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in))) {
String userInput;
out.println("unit id: 1\nunit pos: 11S MS 4859 9849");
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("from client: " + in.readLine());
}
} catch (UnknownHostException e) {
System.err.println("Don't know about host " + hostName);
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to " + hostName);
System.exit(1);
}
}
}
\ No newline at end of file
//package positionserver;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.PrintWriter;
public class SnellPositionServer {
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
try (ServerSocket serverSocket = new ServerSocket(8005);
Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));) {
System.out.println("Client connected on port 8005");
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Received message: " + inputLine + " from " + clientSocket.toString());
out.println(inputLine);
}
} catch (IOException e) {
System.out.println("Exception when trying to listen on port 8005");
}
}
}
\ No newline at end of file
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