package MV3500Cohort2018JanuaryMarch.homework1; //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; /** * homework assignment * @author AJSNELL */ public class SnellPositionClient { /** * Program invocation, execution starts here * @param args command-line arguments */ public static void main(String[] args) { String hostName = args[0]; // poor practice, ought to throw meaningful exception message 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); } } }