home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-16 | 1.5 KB | 83 lines |
- // The Virtual Light Company 1996
- //
- // From Chapter 20: Late Night VRML 2.0 and java
- //
- // This is the Registry server starter class.
-
- package registry;
-
- import java.net.*;
- import java.io.*;
- import registry.*;
-
- public class Registry extends Thread
- {
- private boolean debug;
-
- private int _port;
- private boolean server_available = false;
- private ServerSocket listen_socket = null;
- private RegistryManager manager;
- private RegistryServer server;
-
- private ThreadGroup thread_group;
-
- public Registry(int port, ThreadGroup tg, RegistryServer rserver, boolean debug)
- {
- super(tg, "Registry thread");
-
- thread_group = tg;
-
- this.debug = debug;
- _port = port;
-
- System.out.println("Starting Registry Server on TCP port " + port);
-
- try
- {
- listen_socket = new ServerSocket(port);
- }
- catch(IOException e)
- {
- System.err.println("Unable to open Registry socket " + e.getMessage());
- return;
- }
-
- manager = new RegistryManager();
-
- server = rserver;
- server_available = true;
- }
-
- public void run()
- {
- Socket new_connection;
- RegistryMessage msg;
-
- // if the server failed to start then exit and do nothing.
- if(!server_available)
- return;
-
- while(true)
- {
- try
- {
- new_connection = listen_socket.accept();
- Thread.yield();
- }
- catch(IOException e)
- {
- System.err.println("Registry Socket accept error " + e.getMessage());
- new_connection = null;
- }
-
- if(new_connection != null)
- {
- msg = new RegistryMessage(new_connection, thread_group, server, debug);
- msg.start();
- manager.add(msg);
- }
- }
- }
- }
-