26 |
|
socket = new DatagramSocket(port); |
27 |
|
} |
28 |
|
catch (BindException e){ |
29 |
< |
System.out.println("Some other process is already listening on port "+port+"."); |
30 |
< |
System.out.println("Please specify another port number on the command line."); |
29 |
> |
logger.write(this.toString(), Logger.SYSMSG, "Could not start the UDPReader thread on port "+port+" as this port was already in use."); |
30 |
|
return; |
31 |
|
} |
32 |
|
catch (Exception e){ |
33 |
< |
System.out.println("An exception occured while creating the DatagramSocket."); |
33 |
> |
logger.write(this.toString(), Logger.SYSMSG, "Could not start the UDPReader thread on port "+port+"."); |
34 |
|
return; |
35 |
|
} |
36 |
|
|
37 |
< |
System.out.println("UDPReader ready and listening for UDP packets on port "+port); |
37 |
> |
logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+port); |
38 |
|
|
39 |
|
byte[] buf; |
41 |
– |
UDPReaderThread t = new UDPReaderThread(); |
40 |
|
|
41 |
|
boolean running = true; |
42 |
|
while (running){ |
45 |
|
// receive request |
46 |
|
DatagramPacket packet = new DatagramPacket(buf, buf.length); |
47 |
|
socket.receive(packet); |
48 |
+ |
UDPReaderThread t = new UDPReaderThread(); |
49 |
|
t.run(packet); |
50 |
|
} |
51 |
|
catch (IOException e) { |
52 |
< |
System.out.println("An exception occured in the UDPReader!"); |
53 |
< |
e.printStackTrace(); |
52 |
> |
logger.write(this.toString(), Logger.SYSMSG, "The UDPReader thread has been shut down as an exception occured: "+e); |
53 |
> |
return; |
54 |
|
} |
55 |
|
} |
56 |
|
socket.close(); |