|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
NetworkIO.ServerBase
public class ServerBase
A ServerBase will recieved, and can make, connections to other servers, or clients that use this NetworkIO package.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected java.util.HashMap |
connections
|
protected NetworkLogger |
logger
|
protected int |
port
|
protected java.net.ServerSocket |
serverSocket
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
ServerBase(int port)
Creates a new instance of ServerBase |
Method Summary | |
---|---|
void |
addConnection(java.lang.String host,
int port)
Adds a connection. |
void |
addConnectionListener(ConnectionListener listener)
Adds a ConnectionListener to listen to any new connections or lost connections. |
void |
addNetworkListener(NetworkListener listener)
Adds a NetworkListener to process any incomming Messages. |
ClientBase |
getClientBase(java.net.Socket socket)
Returns the ClientBase associated with the Socket connection. |
void |
run()
Recieves and processes all incoming connections. |
void |
send(Message message,
java.net.Socket socket)
Sends a message to a specific connection. |
void |
sendToAll(Message message)
Sends a Message to all connected clients. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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 |
---|
protected NetworkLogger logger
protected java.net.ServerSocket serverSocket
protected java.util.HashMap connections
protected int port
Constructor Detail |
---|
public ServerBase(int port)
port
- The port on which to host this server.Method Detail |
---|
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void addConnection(java.lang.String host, int port)
host
- The host computer running another server.port
- The port of the computer on which to connect to.public void send(Message message, java.net.Socket socket) throws java.lang.Exception
message
- The Message to send.socket
- The Socket connection to send the Message to.
java.lang.Exception
- Any exception that occurs while sending the message.public ClientBase getClientBase(java.net.Socket socket)
socket
- The Socket associated with the ClientBase.
public void sendToAll(Message message) throws java.lang.Exception
message
- The Message to send.
java.lang.Exception
- Any exception that occurs while trying to send the Message.public void addNetworkListener(NetworkListener listener)
listener
- The NetworkListener to listen to all incomming Messages.public void addConnectionListener(ConnectionListener listener)
listener
- The ConnectionListener to listen to any new connections or lost connections.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |