client_java_tcp - new DataOutputStream(...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import*; import*; /* Code used from Kurose and Ross book (Computer Networking): type BufferedReader, Socket, DataOutputStream. */ class client_java_tcp { public static void main(String argv[]) throws Exception { String address, expr; int port; BufferedReader inFromUser = new BufferedReader( new InputStreamReader( ); System.out.print("Enter server name or IP address: "); address = inFromUser.readLine(); System.out.print("Enter port: "); port = Integer.parseInt( inFromUser.readLine() ); if (port < 0 || port > 65535) { System.out.println("Invalid port number. Terminating."); System.exit(1); } try{ Socket clientSocket = new Socket(address, port); System.out.print("Enter expression: "); DataOutputStream outToServer =
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: new DataOutputStream( clientSocket.getOutputStream() ); BufferedReader inFromServer = new BufferedReader( new InputStreamReader(clientSocket.getInputStream())); expr = inFromUser.readLine(); outToServer.writeBytes(expr + " y" + '\n'); String answer = inFromServer.readLine(); System.out.println(); System.out.println(str); int ctr = Math.abs( (int) Float.parseFloat(answer) ); for (int i = 1; i <= ctr; i++) { str = inFromServer.readLine(); System.out.println(str); } clientSocket.close(); } catch (UnknownHostException e) { System.err.println("Could not connect to server. Terminating."); } catch (ConnectException e) { System.err.println("Could not connect to server. Terminating."); } } }...
View Full Document

This note was uploaded on 02/19/2012 for the course ENGR 361 taught by Professor Drexel during the Spring '12 term at Bloomsburg.

Page1 / 2

client_java_tcp - new DataOutputStream(...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online