|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.lang.Thread
soc.server.genericServer.Server
a general purpose server.
This is the real stuff. Server subclasses won't have to care about reading/writing on the net, data consistency among threads, etc.
Newly connecting clients arrive in run(),
start a thread for the server side of their Connection or LocalStringConnection,
and are integrated into server data via addConnection(StringConnection)
called from that thread.
The first message over the connection should be from the server to the client,
in newConnection1(StringConnection) or newConnection2(StringConnection).
| Nested Class Summary | |
(package private) class |
Server.Command
|
protected class |
Server.NetStringServerSocket
Uses ServerSocket to implement StringServerSocket over a network. |
(package private) class |
Server.Treater
|
| Field Summary | |
protected java.util.Hashtable |
conns
the named connections |
protected java.lang.Exception |
error
|
java.util.Vector |
inQueue
in process of connecting |
protected int |
numberOfConnections
total number of connections made |
protected int |
port
|
(package private) StringServerSocket |
ss
|
protected java.lang.String |
strSocketName
|
protected java.util.Vector |
unnamedConns
the newly connected, unnamed connections. |
(package private) boolean |
up
|
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
Server(int port)
start listening to the given port |
|
Server(java.lang.String stringSocketName)
start listening to the given local string port (practice game) |
|
| Method Summary | |
void |
addConnection(StringConnection c)
Add a connection to the system. |
protected void |
broadcast(java.lang.String m)
Broadcast a SOCmessage to all connected clients, named and unnamed. |
protected int |
connectionCount()
|
protected StringConnection |
getConnection(java.lang.Object connKey)
Given a key data, return the connected client. |
protected java.util.Enumeration |
getConnections()
|
boolean |
isUp()
|
protected void |
leaveConnection(StringConnection c)
placeholder for doing things when a connection is closed. |
void |
nameConnection(StringConnection c)
Name a current connection to the system. |
protected boolean |
newConnection1(StringConnection c)
placeholder for doing things when a new connection comes, part 1 - decide whether to accept. |
protected void |
newConnection2(StringConnection c)
placeholder for doing things when a new connection comes, part 2 - has been accepted and added to a connection list. |
abstract void |
processCommand(java.lang.String str,
StringConnection con)
DOCUMENT ME! |
void |
removeConnection(StringConnection c)
remove a connection from the system; synchronized on list of connections. |
protected void |
removeConnectionCleanup(StringConnection c)
do cleanup after a remove connection |
void |
run()
run method for Server |
protected void |
serverDown()
placeholder for doing things when server gets down |
void |
stopServer()
The server is being cleanly stopped, disconnect all the connections. |
void |
treat(java.lang.String s,
StringConnection c)
treat a request from the given connection |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
StringServerSocket ss
boolean up
protected java.lang.Exception error
protected int port
protected java.lang.String strSocketName
protected int numberOfConnections
protected java.util.Hashtable conns
protected java.util.Vector unnamedConns
public java.util.Vector inQueue
| Constructor Detail |
public Server(int port)
public Server(java.lang.String stringSocketName)
| Method Detail |
protected StringConnection getConnection(java.lang.Object connKey)
connKey - Object key data, as in StringConnection.getData(); if null, returns null
protected java.util.Enumeration getConnections()
protected int connectionCount()
public boolean isUp()
public void run()
run in interface java.lang.Runnable
public void treat(java.lang.String s,
StringConnection c)
public abstract void processCommand(java.lang.String str,
StringConnection con)
str - DOCUMENT ME!con - DOCUMENT ME!protected void serverDown()
protected boolean newConnection1(StringConnection c)
unnamedConns or conns).
Unless you override this method, always returns true.
Should send a message to the client in either newConnection1(StringConnection)
or newConnection2(StringConnection).
Note that addConnection(StringConnection) won't close the channel or
take other action to disconnect a rejected client.
SYNCHRONIZATION NOTE: During the call to newConnection1, the monitor lock of
unnamedConns is held. Thus, defer as much as possible until
newConnection2(StringConnection) (after the connection is accepted).
c - incoming connection to evaluate and act on
StringConnection.disconnectSoft().addConnection(StringConnection),
newConnection2(StringConnection),
nameConnection(StringConnection)protected void newConnection2(StringConnection c)
newConnection1(StringConnection),
no connection-list locks are held when this method is called.
protected void leaveConnection(StringConnection c)
public void stopServer()
serverDown() before disconnect; if your child class has more work
to do (such as sending a final message to all clients, or
disconnecting from a database), override serverDown() or stopServer().
Check isUp() before calling.
public void removeConnection(StringConnection c)
leaveConnection(StringConnection) will be called,
after calling StringConnection.disconnect() on c.
c - Connection to remove; will call its disconnect() method
and remove it from the server state.protected void removeConnectionCleanup(StringConnection c)
public void addConnection(StringConnection c)
App-specific work should be done by overriding
newConnection1(StringConnection) and
newConnection2(StringConnection).
c - Connecting client; its key data (StringConnection.getData()) must not be null.nameConnection(StringConnection),
removeConnection(StringConnection)
public void nameConnection(StringConnection c)
throws java.lang.IllegalArgumentException
c - Connected client; its key data (StringConnection.getData()) must not be null.
java.lang.IllegalArgumentException - If c isn't already connected, or If c.getData() returns nulladdConnection(StringConnection)protected void broadcast(java.lang.String m)
m - SOCmessage string, generated by SOCMessage.toCmd()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||