public class DefaultServerConnection extends java.lang.Object implements ServerConnection
Constructor and Description |
---|
DefaultServerConnection(@NotNull Model model,
@Nullable com.realtime.crossfire.jxclient.util.DebugWriter debugProtocol)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
Adds a
ClientSocketListener to notify. |
void |
connect(@NotNull java.lang.String hostname,
int port)
Attempts to connect the client to a server.
|
void |
disconnect(@NotNull java.lang.String reason)
Disconnects from the server.
|
void |
removeClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
Removes a
ClientSocketListener to notify. |
void |
start()
Starts operation.
|
void |
stop()
Stops operation.
|
void |
writePacket(byte[] packet,
int length,
@NotNull ClientSocketMonitorCommand monitor)
Writes a Crossfire Message on the socket, so it is sent to the server.
|
public DefaultServerConnection(@NotNull @NotNull Model model, @Nullable @Nullable com.realtime.crossfire.jxclient.util.DebugWriter debugProtocol) throws java.io.IOException
model
- the model to updatedebugProtocol
- tf non-null
, write all protocol commands to
this writerjava.io.IOException
- if an internal error occurspublic void start()
public void stop() throws java.lang.InterruptedException
java.lang.InterruptedException
- if stopping was interruptedpublic void addClientSocketListener(@NotNull @NotNull ClientSocketListener clientSocketListener)
ServerConnection
ClientSocketListener
to notify.addClientSocketListener
in interface ServerConnection
clientSocketListener
- the client socket listener to addpublic void removeClientSocketListener(@NotNull @NotNull ClientSocketListener clientSocketListener)
ServerConnection
ClientSocketListener
to notify.removeClientSocketListener
in interface ServerConnection
clientSocketListener
- the client socket listener to removepublic void writePacket(byte[] packet, int length, @NotNull @NotNull ClientSocketMonitorCommand monitor)
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 ignoredmonitor
- the monitor command to send to script processespublic void connect(@NotNull @NotNull java.lang.String hostname, int port)
ServerConnection
connect
in interface ServerConnection
hostname
- the hostname to connect toport
- the port to connect topublic void disconnect(@NotNull @NotNull java.lang.String reason)
ServerConnection
disconnect
in interface ServerConnection
reason
- the reason for the disconnect