|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfeud.clientserver.SimpleServer
As the name indicates, this is a simple server class. Once started, it opens a TCP-socket for clients to connect
as well as an (optional) UDP datagram socket (if possible) that broadcasts this server's ip and port for allowing
to implement a simple server browser.
The communication between this server and its clients is done via DataContainers, which are simple Wrappers for
primitive values (and Strings) into byte arrays.
Field Summary | |
static int |
DEFAULT_PORT
The default tcp port |
static int |
UDP_DEFAULT_PORT
The default UDP port |
Constructor Summary | |
SimpleServer(int tcpPort,
int udpPort,
boolean doBroadcast,
java.lang.String serverName)
Creates a new Server. |
Method Summary | |
void |
addListener(DataTransferListener sl)
Adds a new DataTransferListener to the server. |
void |
addLoginListener(ClientLoginListener ctl)
Adds a new ClientLoginListener to the server. |
void |
addLogoutListener(ClientLogoutListener ctl)
Adds a new ClientLogoutListener to the server. |
void |
broadcast(DataContainer dc)
Adds a DataContainer to the broadcast-queue. |
void |
shutDown()
Shuts down the server. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_PORT
public static final int UDP_DEFAULT_PORT
Constructor Detail |
public SimpleServer(int tcpPort, int udpPort, boolean doBroadcast, java.lang.String serverName)
tcpPort
- The tcp port to which a client can connect with this server. This port has to be open and unused or otherwise, the server won't start.udpPort
- the udp port for broadcasting the server's ip and port (and player count). If this port is not available, the broadcasting thread will
terminate, but the server will run anyway.doBroadcast
- If true, the broadcasting thread will be spawned. Otherwise, it won't.serverName
- The name of the server. Should be unique but doesn't have to.Method Detail |
public void addListener(DataTransferListener sl)
sl
- the listenerpublic void addLogoutListener(ClientLogoutListener ctl)
ctl
- the listenerpublic void addLoginListener(ClientLoginListener ctl)
ctl
- the listenerpublic void shutDown()
public void broadcast(DataContainer dc)
dc
- the DataContainer that should be enqueued
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |