home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-16 | 1.6 KB | 85 lines |
- // The Virtual Light Company 1996
- //
- // From Chapter 20: Late Night VRML 2.0 and java
- //
- // This is the update data server starter class.
-
- package update;
-
- import java.net.*;
- import java.io.*;
- import filter.UserServer;
-
- public class Update extends Thread
- {
- private static final int BUFFER_LENGTH = 1024;
- private int _port;
- private boolean server_available = false;
- private DatagramSocket listen_socket = null;
- private UpdateManager manager = null;
- private UserServer server;
-
- private ThreadGroup thread_group;
-
- public Update(int port, ThreadGroup tg, UserServer userver)
- {
- super(tg, "Update Server Thread");
-
- thread_group = tg;
-
- _port = port;
-
- System.out.println("Starting Filter Server on UDP port " + port);
- try
- {
- listen_socket = new DatagramSocket(port);
- }
- catch(IOException e)
- {
- System.err.println("Unable to open Update socket " + e.getMessage());
- return;
- }
-
- manager = new UpdateManager();
-
- server = userver;
- server_available = true;
- }
-
- public void run()
- {
- byte[] buffer;
- DatagramPacket packet;
- UpdateMessage a_update;
-
- // if the server failed to start then exit and do nothing.
- if(!server_available)
- return;
-
- // tell the chat manager to start running
- manager.start();
-
- // now process the input.
- while(true)
- {
- buffer = new byte[BUFFER_LENGTH];
- packet = new DatagramPacket(buffer, BUFFER_LENGTH);
-
- try
- {
- listen_socket.receive(packet);
- Thread.yield();
- }
- catch(IOException e)
- {
- System.err.println("packet error");
- }
-
- a_update = new UpdateMessage(packet, thread_group, server);
- a_update.run();
- manager.add(a_update);
- }
- }
- }
-
-