25 |
|
} |
26 |
|
} |
27 |
|
|
28 |
< |
DatagramSocket socket = new DatagramSocket(port); |
28 |
> |
DatagramSocket socket = null; |
29 |
> |
try { |
30 |
> |
socket = new DatagramSocket(port); |
31 |
> |
} |
32 |
> |
catch (BindException e){ |
33 |
> |
System.out.println("Some other process is already listening on port "+port+"."); |
34 |
> |
System.out.println("Please specify another port number on the command line."); |
35 |
> |
System.exit(0); |
36 |
> |
} |
37 |
> |
|
38 |
|
System.out.println("UDPReader ready and listening for UDP packets on port "+port); |
39 |
|
|
40 |
+ |
byte[] buf; |
41 |
+ |
UDPReaderThread t = new UDPReaderThread(); |
42 |
+ |
|
43 |
|
boolean running = true; |
44 |
|
while (running){ |
45 |
+ |
System.gc(); |
46 |
|
try { |
47 |
< |
byte[] buf = new byte[packetSizeLimit]; |
47 |
> |
buf = new byte[packetSizeLimit]; |
48 |
|
// receive request |
49 |
|
DatagramPacket packet = new DatagramPacket(buf, buf.length); |
50 |
|
socket.receive(packet); |
51 |
< |
UDPReaderThread thread = new UDPReaderThread(packet); |
39 |
< |
thread.run(); |
51 |
> |
t.run(packet); |
52 |
|
} |
53 |
|
catch (IOException e) { |
54 |
|
System.out.println("An exception occured in the UDPReader!"); |