server_java_udp - import import import...

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

View Full Document Right Arrow Icon
import*; import java.util.*; /* Code used from Kurose and Ross book (Computer Networking): type BufferedReader, DatagramPacket, InetAddress. */ class server_java_udp { public static void main(String[] args) throws Exception { String clientExpr, leng; int portServer = Integer.parseInt( args[0] ); int portClient; DatagramSocket serverSocket = new DatagramSocket(portServer); byte[] receiveLength = new byte[1024]; byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; Stack<Float> operand = new Stack<Float>(); Stack<Character> operator = new Stack<Character>(); while (true) // make sure to delete when finalizing { DatagramPacket length = new DatagramPacket(receiveLength, receiveLength.length); serverSocket.receive(length); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); leng = new String(length.getData()); clientExpr = new String(receivePacket.getData()); InetAddress IPAddress = receivePacket.getAddress(); portClient = receivePacket.getPort(); // program keeps on throwing exception after sending ACK /* leng = leng.trim(); clientExpr = clientExpr.trim(); // confirmation of length message if (Integer.parseInt(leng) != clientExpr.length()) { System.out.println("Did not receive valid expression from client. Terminating.");
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 / 5

server_java_udp - import import import...

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