Class DefaultServerConnection
java.lang.Object
com.realtime.crossfire.jxclient.server.server.DefaultServerConnection
- All Implemented Interfaces:
ServerConnection
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.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultServerConnection(@NotNull GuiStateManager guiStateManager, @Nullable DebugWriter debugProtocol) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClientSocketListener(@NotNull ClientSocketListener clientSocketListener) Adds aClientSocketListenerto notify.voidAttempts to connect the client to a server.voiddisconnect(@NotNull String reason) Disconnects from the server.voidremoveClientSocketListener(@NotNull ClientSocketListener clientSocketListener) Removes aClientSocketListenerto notify.voidstart()Starts operation.voidstop()Stops operation.voidwritePacket(byte @NotNull [] packet, int length, @NotNull ClientSocketMonitorCommand monitor) Writes a Crossfire Message on the socket, so it is sent to the server.
-
Constructor Details
-
DefaultServerConnection
public DefaultServerConnection(@NotNull @NotNull GuiStateManager guiStateManager, @Nullable @Nullable DebugWriter debugProtocol) throws IOException Creates a new instance.- Parameters:
guiStateManager- the gui state manager to updatedebugProtocol- tf non-null, write all protocol commands to this writer- Throws:
IOException- if an internal error occurs
-
-
Method Details
-
start
public void start()Starts operation. -
stop
Stops operation.- Throws:
InterruptedException- if stopping was interrupted
-
addClientSocketListener
Description copied from interface:ServerConnectionAdds aClientSocketListenerto notify.- Specified by:
addClientSocketListenerin interfaceServerConnection- Parameters:
clientSocketListener- the client socket listener to add
-
removeClientSocketListener
Description copied from interface:ServerConnectionRemoves aClientSocketListenerto notify.- Specified by:
removeClientSocketListenerin interfaceServerConnection- Parameters:
clientSocketListener- the client socket listener to remove
-
writePacket
public void writePacket(byte @NotNull [] packet, int length, @NotNull @NotNull ClientSocketMonitorCommand monitor) Writes a Crossfire Message on the socket, so it is sent to the server.- Parameters:
packet- the packet to be sent; it does not include the length bytes but only actual payload datalength- the length ofpacket; if the array is larger, excess data is ignoredmonitor- the monitor command to send to script processes
-
connect
Description copied from interface:ServerConnectionAttempts to connect the client to a server.- Specified by:
connectin interfaceServerConnection- Parameters:
hostname- the hostname to connect toport- the port to connect to
-
disconnect
Description copied from interface:ServerConnectionDisconnects from the server. Does nothing if not connected.- Specified by:
disconnectin interfaceServerConnection- Parameters:
reason- the reason for the disconnect
-