server_java_udp

server_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.net.*; 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.

Page1 / 5

server_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