client_java_udp

client_java_udp - import java.io.*; import java.net.*; /*...

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

View Full Document Right Arrow Icon
import java.io.*; import java.net.*; /* Code used from Kurose and Ross book (Computer Networking): type BufferedReader, DatagramSocket, byte[] */ class client_java_udp { public static void main(String args[]) throws Exception { String address, expr, length; int port; BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in) ); 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 { DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName(address); byte[] sendData = new byte[1024]; byte[] sendLength = new byte[1024]; byte[] receiveData = new byte[1024]; System.out.print("Enter expression: "); expr = inFromUser.readLine(); length = Integer.toString(expr.length()); sendLength = length.getBytes(); // sending length of message to server
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the 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 / 3

client_java_udp - import java.io.*; import java.net.*; /*...

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