//SocketClient.java // usage : java SocketClient // default port is 1500 import java.net.*; import java.io.*; public class SocketClient { public static void main(String[] args) { int port = 1500; String server = "localhost"; Socket socket = null; String lineToBeSent; BufferedReader input; PrintWriter output; int ERROR = 1; // read arguments if(args.length == 2) { server = args[0]; try { port = Integer.parseInt(args[1]); } catch (Exception e) { System.out.println("server port = 1500 (default)"); port = 1500; } } // connect to server try { socket = new Socket(server, port); System.out.println("Connected with server " + socket.getInetAddress() + ":" + socket.getPort()); } catch (UnknownHostException e) { System.out.println(e); System.exit(ERROR); } catch (IOException e) { System.out.println(e); System.exit(ERROR); } try { System.out.println("inside reading file"); //input = new BufferedReader(new InputStreamReader(System.in)); input = new BufferedReader(new FileReader("steer.txt")); output = new PrintWriter(socket.getOutputStream(),true); // get user input and transmit it to server lineToBeSent = input.readLine(); while(lineToBeSent!=null) { output.println(lineToBeSent); System.out.println("send line: " + lineToBeSent); Thread t=Thread.currentThread(); t.sleep(2000); lineToBeSent = input.readLine(); }//end while input.close(); output.close(); } catch (Exception e) { System.out.println(e); } try { socket.close(); } catch (IOException e) { System.out.println(e); } } }