summaryrefslogtreecommitdiff
path: root/test/java.net/ServerDatagram.java
blob: 17ce44a278b66ce9b208c2620475a048086428ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* Server Datagram Socket for testing */

import java.io.*;
import java.net.*;

public class ServerDatagram implements Runnable
{

private DatagramSocket s;

public static void
main(String[] argv) throws IOException
{
  ServerDatagram sd = new ServerDatagram(37900);
  sd.run();
}

public
ServerDatagram(int port) throws SocketException
{
  s = new DatagramSocket(port);
  System.out.println("Server datagram socket created");
}

public void 
run()
{
  try
    {
      byte[] buf = new byte[65535];

      DatagramPacket p = new DatagramPacket(buf, buf.length);

      p.setLength(buf.length);

      s.receive(p);
      System.out.println("ServerDatagram: received " + p.getLength() +
         " bytes from " + p.getAddress().getHostName() + ":" +
         p.getPort());

      if (p.getLength() != 65332)
        throw new IOException("Incorrect data size");
      System.out.println("PASSED max values test");
    }
  catch (IOException e)
    {
      System.out.print("FAILED: ServerDatagram caught an exception: " + e);
    }
}

}