java.lang.Object com.realtime.crossfire.jxclient.server.server.DefaultServerConnection
public abstract class DefaultServerConnection
One of the two most important classes, ServerConnection performs most of the network-related work. It either decodes commands sent by the server itself, or delegates their processing to other classes, like Map or Faces.
Field Summary | |
---|---|
private ClientSocket |
clientSocket
The ClientSocket instance used to connect to Crossfire servers. |
Constructor Summary | |
---|---|
protected |
DefaultServerConnection(DebugWriter debugProtocol)
Creates a new instance. |
Method Summary | |
---|---|
void |
addClientSocketListener(ClientSocketListener clientSocketListener)
Adds a ClientSocketListener to notify. |
void |
connect(java.lang.String hostname,
int port)
Attempts to connect the client to a server. |
void |
disconnect(java.lang.String reason)
Disconnects from the server. |
void |
removeClientSocketListener(ClientSocketListener clientSocketListener)
Removes a ClientSocketListener to notify. |
void |
start()
Starts operation. |
void |
stop()
Stops operation. |
protected void |
writePacket(byte[] packet,
int length)
Writes a Crossfire Message on the socket, so it is sent to the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@NotNull private final ClientSocket clientSocket
ClientSocket
instance used to connect to Crossfire servers.
Constructor Detail |
---|
protected DefaultServerConnection(@Nullable DebugWriter debugProtocol) throws java.io.IOException
debugProtocol
- tf non-null
, write all protocol
commands to this writer
java.io.IOException
- if an internal error occursMethod Detail |
---|
public void addClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
ClientSocketListener
to notify.
addClientSocketListener
in interface ServerConnection
clientSocketListener
- the client socket listener to addpublic void connect(@NotNull java.lang.String hostname, int port)
connect
in interface ServerConnection
hostname
- the hostname to connect toport
- the port to connect topublic void disconnect(@NotNull java.lang.String reason)
disconnect
in interface ServerConnection
reason
- the reason for the disconnectpublic void removeClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
ClientSocketListener
to notify.
removeClientSocketListener
in interface ServerConnection
clientSocketListener
- the client socket listener to removepublic void start()
public void stop() throws java.lang.InterruptedException
java.lang.InterruptedException
- if stopping was interruptedprotected void writePacket(@NotNull byte[] packet, int length)
packet
- the packet to be sent; it does not include the length bytes
but only actual payload datalength
- the length of packet
; if the array is larger,
excess data is ignored