ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/filter/UDPReader.java
Revision: 1.3
Committed: Thu Nov 23 09:08:07 2000 UTC (23 years, 5 months ago) by pjm2
Branch: MAIN
Changes since 1.2: +5 -4 lines
Log Message:
Altered UDPReader and FilterThread so that the UDP packet data is now
passed via the FilterThread's constructor.

File Contents

# Content
1 import java.io.*;
2 import java.net.*;
3 import java.util.*;
4 import uk.ac.ukc.iscream.core.*;
5 import uk.ac.ukc.iscream.filter.*;
6
7 // This class contains the main method to be run by
8 // the filter children. It harvests UDP traffic.
9 //
10 public class UDPReader extends Thread{
11
12 // It is normal to use this constructor in preference
13 // to any other in this class.
14 public UDPReader(int port, Filter parent, Logger logger){
15 this.logger = logger;
16 this.port = port;
17 this.parent = parent;
18 }
19
20 public UDPReader(Filter parent, Logger logger){
21 this(4589, parent, logger);
22 }
23
24 public void run() {
25
26 DatagramSocket socket = null;
27 try {
28 socket = new DatagramSocket(port);
29 }
30 catch (BindException e){
31 logger.write(this.toString(), Logger.SYSMSG, "Could not start the UDPReader thread on port "+port+" as this port was already in use.");
32 return;
33 }
34 catch (Exception e){
35 logger.write(this.toString(), Logger.SYSMSG, "Could not start the UDPReader thread on port "+port+".");
36 return;
37 }
38
39 logger.write(this.toString(), Logger.SYSMSG, "UDPReader thread ready and listening for UDP packets on port "+port);
40
41 byte[] buf;
42
43 boolean running = true;
44 while (running){
45 try {
46
47 // receive request and pass on to the FilterThread.
48 buf = new byte[packetSizeLimit];
49 DatagramPacket packet = new DatagramPacket(buf, buf.length);
50 socket.receive(packet);
51 FilterThread t = new FilterThread(parent, packet);
52 t.start();
53
54 }
55 catch (IOException e) {
56 logger.write(this.toString(), Logger.SYSMSG, "The UDPReader thread has been shut down as an exception occured: "+e);
57 return;
58 }
59 }
60 socket.close();
61 }
62
63
64 Logger logger;
65 int port;
66 Filter parent;
67
68 final int packetSizeLimit = 8192;
69
70 }