PR target/27599
[official-gcc.git] / libjava / classpath / test / java.net / ServerDatagram.java
blob17ce44a278b66ce9b208c2620475a048086428ff
1 /* Server Datagram Socket for testing */
3 import java.io.*;
4 import java.net.*;
6 public class ServerDatagram implements Runnable
9 private DatagramSocket s;
11 public static void
12 main(String[] argv) throws IOException
14 ServerDatagram sd = new ServerDatagram(37900);
15 sd.run();
18 public
19 ServerDatagram(int port) throws SocketException
21 s = new DatagramSocket(port);
22 System.out.println("Server datagram socket created");
25 public void
26 run()
28 try
30 byte[] buf = new byte[65535];
32 DatagramPacket p = new DatagramPacket(buf, buf.length);
34 p.setLength(buf.length);
36 s.receive(p);
37 System.out.println("ServerDatagram: received " + p.getLength() +
38 " bytes from " + p.getAddress().getHostName() + ":" +
39 p.getPort());
41 if (p.getLength() != 65332)
42 throw new IOException("Incorrect data size");
43 System.out.println("PASSED max values test");
45 catch (IOException e)
47 System.out.print("FAILED: ServerDatagram caught an exception: " + e);