CS101 Package Problem Set Javadocs

cs101.net
Class Server

java.lang.Object
  extended bycs101.net.Server
All Implemented Interfaces:
java.lang.Runnable

public class Server
extends java.lang.Object
implements java.lang.Runnable

Generic Server class: broadcasts whatever messages it receives to all clients other than the message's originator. Spawns one thread to listen and multiple others to handle the clients as they connect.

Takes a single optional argument to specify the port. Otherwise spawns a UI dialog to get connection information from the user.

Some hints taken from ORA Servers.

Copyright 1996 Massachusetts Institute of Technology

Version:
$Id: Server.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $
Author:
Todd C. Parnell, tparnell@ai.mit.edu, Maciej Stachowiak, maciej@ai.mit.edu, Emil Sit, sit@mit.edu, Joshua Reuben Brown, reuben@ai.mit.edu, Lynn Andrea Stein, las@ai.mit.edu
See Also:
RunServer, Client, ServerDialog

Field Summary
protected  java.util.Vector babySitters
          list of BabySitters to handle each client connection
protected  java.net.ServerSocket sock
          the server socket, i.e., the listener
protected  java.lang.Thread spirit
          animating Thread
 
Constructor Summary
Server()
          Creates a server socket.
Server(int port)
          Creates a server socket.
 
Method Summary
protected  void listenOn(int port)
          Helper method to actually open the ServerSocket and intialize other state.
protected  void removeBabySitter(BabySitter bbst)
          Removes a BabySitter for the list of babySitters.
 void run()
          Wait loop to service the ServerSocket.
protected  void sendToAllExcept(java.lang.String s, BabySitter bbst)
          Sends the string passed in to all clients accept the one represented by the BabySitter passed in.
protected  void spawnBabySitter(java.net.Socket s)
          Creates a BabySitter with the client socket passed and adds it to the list of BabySitters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sock

protected java.net.ServerSocket sock
the server socket, i.e., the listener


babySitters

protected java.util.Vector babySitters
list of BabySitters to handle each client connection


spirit

protected java.lang.Thread spirit
animating Thread

Constructor Detail

Server

public Server()
Creates a server socket. Waits for connections. No argument version prompts users for port information.


Server

public Server(int port)
Creates a server socket. Waits for connections.

Parameters:
port - The integer representing the port number to listen on.
Method Detail

listenOn

protected void listenOn(int port)
Helper method to actually open the ServerSocket and intialize other state. Also spawns Thread to continue listening. Called internally.

Parameters:
port - The integer representing the port number to listen on.

run

public void run()
Wait loop to service the ServerSocket. Called by this server's Thread. Should not be called externally. Each time that a connection is recieved, forks a BabySitter to handle that connection.

Specified by:
run in interface java.lang.Runnable

removeBabySitter

protected void removeBabySitter(BabySitter bbst)
Removes a BabySitter for the list of babySitters.

Parameters:
bbst - the BabySitter to be remooved from use.

spawnBabySitter

protected void spawnBabySitter(java.net.Socket s)
Creates a BabySitter with the client socket passed and adds it to the list of BabySitters.

Parameters:
s - the client socket that this BabySitter will handle

sendToAllExcept

protected void sendToAllExcept(java.lang.String s,
                               BabySitter bbst)
Sends the string passed in to all clients accept the one represented by the BabySitter passed in.

Parameters:
s - the string to send
bbst - the BabySitter that handle the client that we don't want to send to (the client that the message came from).

CS101 Package Problem Set Javadocs