--- experimental/server/XMLReader/UDPReader.java 2000/11/20 09:28:18 1.5 +++ experimental/server/XMLReader/UDPReader.java 2000/11/21 09:15:06 1.6 @@ -3,28 +3,24 @@ import java.net.*; import java.util.*; // This class contains the main method to be run by -// the filter children. It harvests UDP traffic +// the filter children. It harvests UDP traffic. // // -public class UDPReader { +public class UDPReader extends Thread{ - public static void main(String[] args) throws IOException { + // It is normal to use this constructor in preference + // to any other in this class. + public UDPReader(int port, Logger logger){ + this.logger = logger; + this.port = port; + } + + public UDPReader(Logger logger){ + this(4589, logger); + } - // default UDP listening port. - int port = 4589; - final int packetSizeLimit = 8192; + public void run() { - // Allow the user to choose their own port number. - if (args.length == 1){ - try { - port = new Integer(args[0]).intValue(); - } - catch (Exception e){ - // If something went wrong, use the default again. - port = 4589; - } - } - DatagramSocket socket = null; try { socket = new DatagramSocket(port); @@ -32,8 +28,12 @@ public class UDPReader { catch (BindException e){ System.out.println("Some other process is already listening on port "+port+"."); System.out.println("Please specify another port number on the command line."); - System.exit(0); + return; } + catch (Exception e){ + System.out.println("An exception occured while creating the DatagramSocket."); + return; + } System.out.println("UDPReader ready and listening for UDP packets on port "+port); @@ -56,4 +56,11 @@ public class UDPReader { } socket.close(); } + + + Logger logger; + int port; + + final int packetSizeLimit = 8192; + }