|
CS101 Package Problem Set Javadocs | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcs101.net.Server
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
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 |
protected java.net.ServerSocket sock
protected java.util.Vector babySitters
protected java.lang.Thread spirit
| Constructor Detail |
public Server()
public Server(int port)
port - The integer representing the port number to listen on.| Method Detail |
protected void listenOn(int port)
port - The integer representing the port number to listen on.public void run()
run in interface java.lang.Runnableprotected void removeBabySitter(BabySitter bbst)
bbst - the BabySitter to be remooved from use.protected void spawnBabySitter(java.net.Socket s)
s - the client socket that this BabySitter will handle
protected void sendToAllExcept(java.lang.String s,
BabySitter bbst)
s - the string to sendbbst - 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 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||