S
- the type that is sent to clients of this serverR
- the type that is received from clients of this serverpublic abstract class TCPServer<S extends java.io.Serializable,R extends java.io.Serializable>
extends java.lang.Object
Constructor and Description |
---|
TCPServer(int port)
Creates a server on the given port.
|
TCPServer(int port,
java.lang.Class<R> receivingClass)
Creates a server on the given port.
|
TCPServer(int port,
java.lang.Class<R> receivingClass,
Logger logger)
Creates a server on the given port.
|
TCPServer(int port,
Logger logger)
Creates a server on the given port.
|
Modifier and Type | Method and Description |
---|---|
void |
broadcast(S message)
Broadcasts some data to all connected clients
|
java.util.Set<Connection<S,R>> |
getConnections()
Gets the currently connected clients
|
void |
stop()
Tells the server to shut down.
|
public TCPServer(int port) throws java.io.IOException
port
- the port to run off ofjava.io.IOException
- if the server could not be openedpublic TCPServer(int port, java.lang.Class<R> receivingClass) throws java.io.IOException
port
- the port to run off ofreceivingClass
- the type clients will send to this serverjava.io.IOException
- if the server could not be openedpublic TCPServer(int port, java.lang.Class<R> receivingClass, Logger logger) throws java.io.IOException
port
- the port to run off ofreceivingClass
- the type clients will send to this serverlogger
- the logger to log errors to instead of the consolejava.io.IOException
- if the server could not be openedpublic TCPServer(int port, Logger logger) throws java.io.IOException
port
- the port to run off oflogger
- the logger to log errors to instead of the consolejava.io.IOException
- if the server could not be openedpublic void broadcast(S message) throws BroadcastException
message
- the data to sendBroadcastException
- if one or all clients couldn't be sent the messagepublic java.util.Set<Connection<S,R>> getConnections()
public void stop()