|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.esotericsoftware.kryonet.Server
public class Server
Manages TCP and optionally UDP connections from many Clients
.
Constructor Summary | |
---|---|
Server()
Creates a Server with a write buffer size of 16384 and an object buffer size of 2048. |
|
Server(int writeBufferSize,
int objectBufferSize)
|
|
Server(int writeBufferSize,
int objectBufferSize,
com.esotericsoftware.kryo.Kryo kryo)
|
Method Summary | |
---|---|
void |
addListener(Listener listener)
If the listener already exists, it is not added again. |
void |
bind(int tcpPort)
Opens a TCP only server. |
void |
bind(int tcpPort,
int udpPort)
Opens a TCP and UDP server. |
void |
close()
Closes all open connections and the server port(s). |
Connection[] |
getConnections()
Returns the current connections. |
com.esotericsoftware.kryo.Kryo |
getKryo()
Gets the Kryo instance that will be used to serialize and deserialize objects. |
java.lang.Thread |
getUpdateThread()
Returns the last thread that called EndPoint.update(int) for this end point. |
void |
removeListener(Listener listener)
|
void |
run()
Continually updates this end point until EndPoint.stop() is called. |
void |
sendToAllExceptTCP(int connectionID,
java.lang.Object object)
|
void |
sendToAllExceptUDP(int connectionID,
java.lang.Object object)
|
void |
sendToAllTCP(java.lang.Object object)
|
void |
sendToAllUDP(java.lang.Object object)
|
void |
sendToTCP(int connectionID,
java.lang.Object object)
|
void |
sendToUDP(int connectionID,
java.lang.Object object)
|
void |
start()
Starts a new thread that calls EndPoint.run() . |
void |
stop()
Closes this end point and causes EndPoint.run() to return. |
void |
update(int timeout)
Accepts any new connections and reads or writes any pending data for the current connections. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Server()
public Server(int writeBufferSize, int objectBufferSize)
writeBufferSize
- One buffer of this size is allocated for each connected client. Objects are serialized to the write
buffer where the bytes are queued until they can be written to the socket.
Normally the socket is writable and the bytes are written immediately. If the socket cannot be written to and enough serialized objects are queued to overflow the buffer, then the connection will be closed.
The write buffer should be sized at least as large as the largest object that will be sent, plus some head room to allow for some serialized objects to be queued in case the buffer is temporarily not writable. The amount of head room needed is dependent upon the size of objects being sent and how often they are sent.
objectBufferSize
- Two (using only TCP) or four (using both TCP and UDP) buffers of this size are allocated. These
buffers are used to hold the bytes for a single object graph until it can be sent over the network or
deserialized.
The object buffers should be sized at least as large as the largest object that will be sent or received.
public Server(int writeBufferSize, int objectBufferSize, com.esotericsoftware.kryo.Kryo kryo)
Method Detail |
---|
public com.esotericsoftware.kryo.Kryo getKryo()
EndPoint
getKryo
in interface EndPoint
public void bind(int tcpPort) throws java.io.IOException
java.io.IOException
- if the server could not be opened.public void bind(int tcpPort, int udpPort) throws java.io.IOException
java.io.IOException
- if the server could not be opened.public void update(int timeout) throws java.io.IOException
update
in interface EndPoint
timeout
- Wait for up to the specified milliseconds for a connection to be ready to process. May be zero to return
immediately if there are no connections to process.
java.io.IOException
Client.update(int)
,
update(int)
public void run()
EndPoint
EndPoint.stop()
is called.
run
in interface EndPoint
run
in interface java.lang.Runnable
public void start()
EndPoint
EndPoint.run()
.
start
in interface EndPoint
public void stop()
EndPoint
EndPoint.run()
to return.
stop
in interface EndPoint
public void sendToAllTCP(java.lang.Object object)
public void sendToAllExceptTCP(int connectionID, java.lang.Object object)
public void sendToTCP(int connectionID, java.lang.Object object)
public void sendToAllUDP(java.lang.Object object)
public void sendToAllExceptUDP(int connectionID, java.lang.Object object)
public void sendToUDP(int connectionID, java.lang.Object object)
public void addListener(Listener listener)
EndPoint
addListener
in interface EndPoint
public void removeListener(Listener listener)
removeListener
in interface EndPoint
public void close()
close
in interface EndPoint
Client
,
Server
public java.lang.Thread getUpdateThread()
EndPoint
EndPoint.update(int)
for this end point. This can be useful to detect when long running
code will be run on the update thread.
getUpdateThread
in interface EndPoint
public Connection[] getConnections()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |