|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdd.net.NetServer
Base class for network server protocol. There are two classes responsible for the actual communication of messages from a game client to a game server. This is the implementation of the server part of that system. The communication is performed with TCP sockets that stay open for the duration of a game session. Unlike many request systems (like HTTP), both clients and servers can initiate requests. Therefore, both listen for commands from the other end and react accordingly.
The communication between client and server is predouminantly through
a line-oriented text protocol. A command is usually a single line
containing a command word and an arbitrary number of arguments. All
the clients and servers do is interpret the network message and call
the appropriate Handler
that is registered to accept that kind
of message.
The server keeps persistent references to each of the clients that are connected. Messages can be sent to specific clients or broadcast to all connected clients.
There is an implicit protocol implemented between the NetClient and
NetServer. When either side sends the AYT
message, the
response should be the string [yes]
. If an AYT response
is not received, the client is assumed to be in an error state and
disconnects. There is also a handshaking between client and server that
goes as follows:
hello
message in the form
hello uniqueID
register
message of the form
register [uniqueID](note the square brackets are part of the protocol, and are used to delemit the name of the client.
Alternatively, if the client is disconnected, register
can be replaced with reconnect
to inform the server that
the client is replacing an existing client that terminated.
This class provides implementation of the behaviors described above as well as default debugging behaviors. To implement a custom client / server protocol, one can either subclass this class, or instantiate this class and provide it with Handler objects that perform the custom game protocol.
Field Summary | |
static int |
DEFAULT_PORT
Default TCP socket to use for client/server communication. |
static java.lang.String |
DISCOVERY_URL
Well known URL to query for list of servers. |
Logger |
log
Log object used for debugging messages. |
Constructor Summary | |
NetServer()
Creates a new server listening on the default port. |
|
NetServer(java.lang.String serverName)
|
|
NetServer(java.lang.String serverName,
int port)
|
Method Summary | |
void |
addClient(dd.net.NetServer.ServerClient client)
|
void |
broadcast(java.lang.String message)
|
protected java.util.Iterator |
getClientNames()
|
java.util.Set |
getClients()
|
GameServer |
getLobby()
|
void |
handleReconnect(java.lang.String command,
java.lang.String message,
Client c)
|
void |
handleRegister(java.lang.String command,
java.lang.String message,
Client c)
|
boolean |
isReady()
|
boolean |
isRunning()
|
static void |
main(java.lang.String[] args)
|
boolean |
registerVenue(java.lang.String venueName)
|
void |
removeClient(Client client)
|
void |
run()
|
void |
sendTo(java.lang.String user,
java.lang.String message)
|
void |
setGame(GameServer g)
|
void |
stopRunning()
|
void |
unregisterVenue()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public Logger log
public static final java.lang.String DISCOVERY_URL
public static final int DEFAULT_PORT
Constructor Detail |
public NetServer() throws java.io.IOException
public NetServer(java.lang.String serverName) throws java.io.IOException
public NetServer(java.lang.String serverName, int port) throws java.io.IOException
Method Detail |
public boolean registerVenue(java.lang.String venueName) throws java.io.IOException
java.io.IOException
public void unregisterVenue()
public void run()
run
in interface java.lang.Runnable
public void addClient(dd.net.NetServer.ServerClient client)
public void setGame(GameServer g)
public GameServer getLobby()
public void handleRegister(java.lang.String command, java.lang.String message, Client c)
public void handleReconnect(java.lang.String command, java.lang.String message, Client c)
public void removeClient(Client client)
protected java.util.Iterator getClientNames()
public java.util.Set getClients()
public void broadcast(java.lang.String message)
public void sendTo(java.lang.String user, java.lang.String message)
public boolean isReady()
public void stopRunning()
public boolean isRunning()
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |