home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-07 | 1.3 KB | 43 lines |
- // MuServer.java
- // Server Application for multiuser system
- import java.net.*;
- import java.io.*;
- import java.util.*;
-
- class MuServer{
- static Vector clients = new Vector();
-
- public static void main(String[] args){
- ServerSocket server_socket = null;
- Socket client_socket = null;
- int id;
-
- // open socket on PORT
- try{
- server_socket = new ServerSocket(MuProtocol.PORT);
- } catch(IOException e){
- System.out.println("Could not create socket on: " + MuProtocol.PORT + ", " + e);
- System.exit(1);
- }
-
- System.out.println("Waiting for client connection...");
-
- while(true){
- // accept client's request
- try{
- client_socket = server_socket.accept();
- }catch(IOException e){
- System.out.println("Accept failed: " + MuProtocol.PORT + ", " + e);
- System.exit(1);
- }
- System.out.println("Connection established: "
- + client_socket.getInetAddress());
- // create one thread for client request and
- // store it in 'clients' for client management
- id = clients.size();
- clients.insertElementAt(new MuDispatcher(client_socket, clients, id), id);
- System.out.println(" id=" + id);
- }
- }
- }
-