*** UDP Discard Client mod *** package untitled12; import java.net.*; import java.io.*; public class UDPDiscardClientmod { public final static int port = 9; static byte[] buffer = new byte[65507]; /* mod */ public static void main(String[] args) { String hostname; if (args.length > 0) { hostname = args[0]; } else { hostname = "localhost"; } try { DatagramPacket dp = new DatagramPacket(buffer, buffer.length);/* mod */ String theLine; DatagramPacket theOutput; InetAddress server = InetAddress.getByName(hostname); DataInputStream userInput = new DataInputStream(System.in); DatagramSocket theSocket = new DatagramSocket(); while (true) { theLine = userInput.readLine(); if (theLine.equals(".")) break; byte[] data = new byte[theLine.length()]; theLine.getBytes(0, theLine.length(), data, 0); theOutput = new DatagramPacket(data, data.length, server, port); theSocket.send(theOutput); theSocket.receive(dp); /* mod */ String s = new String(dp.getData(), 0, 0, dp.getLength()); /* mod */ System.out.println("Data e hora: " + s);/* mod */ } // end while } // end try catch (UnknownHostException e) { System.err.println(e); } catch (SocketException se) { System.err.println(se); } catch (IOException e) { System.err.println(e); } } // end main } *** UDP Discard Server mod *** package untitled12; import java.net.*; import java.io.*; import java.util.*; /* mod */ public class UDPDiscardServermod { public final static int discardPort = 9; static byte[] buffer = new byte[65507]; public static void main(String[] args) { int port; try { port = Integer.parseInt(args[0]); } catch (Exception e) { port = discardPort; } try { DatagramSocket ds = new DatagramSocket(port); DatagramPacket dp = new DatagramPacket(buffer, buffer.length); while (true) { try { ds.receive(dp); String s = new String(dp.getData(), 0, 0, dp.getLength()); Date d = new Date (); System.out.println(dp.getAddress() + " at port " + dp.getPort() + " says " + s /*+"hora " + d*/); String x = d.toString(); byte[] data = new byte[x.length()]; x.getBytes(0, x.length(), data, 0); dp.setData(data); // DatagramPacket saida = new DatagramPacket(data, data.length, dp.getAddress(), 9); dp.setLength(data.length); ds.send(dp); } catch (IOException e) { System.err.println(e); } } // end while } // end try catch (SocketException se) { System.err.println(se); } // end catch } // end main }