Class ClientSocket
java.lang.Object
com.realtime.crossfire.jxclient.server.socket.ClientSocket
A socket that processes incoming data.
final ClientSocket clientSocket = new ClientSocket(...); clientSocket.writePacket(...); clientSocket.disconnect();
-
Constructor Summary
ConstructorsConstructorDescriptionClientSocket(@NotNull GuiStateManager guiStateManager, @Nullable DebugWriter debugProtocol) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClientSocketListener(@NotNull ClientSocketListener clientSocketListener) Adds aClientSocketListenerto be notified.voidConnects to a server.voiddisconnect(@NotNull String reason, boolean isError) Terminates the connection.voidremoveClientSocketListener(@NotNull ClientSocketListener clientSocketListener) Removes aClientSocketListenerto be notified.voidstart()Starts operation.voidstop()Stops operation.voidwritePacket(byte @NotNull [] buf, int len, @NotNull ClientSocketMonitorCommand monitor) Writes a packet.
-
Constructor Details
-
ClientSocket
public ClientSocket(@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 the socket cannot be created
-
-
Method Details
-
start
public void start()Starts operation. -
stop
Stops operation.- Throws:
InterruptedException- if stopping was interrupted
-
addClientSocketListener
Adds aClientSocketListenerto be notified.- Parameters:
clientSocketListener- the client socket listener to add
-
removeClientSocketListener
Removes aClientSocketListenerto be notified.- Parameters:
clientSocketListener- the client socket listener to remove
-
connect
Connects to a server. Disconnects an existing connection if necessary.- Parameters:
host- the host to connect toport- the port to connect to
-
disconnect
Terminates the connection. Does nothing if not connected.- Parameters:
reason- the reason for the disconnectisError- whether the disconnect is unexpected
-
writePacket
public void writePacket(byte @NotNull [] buf, int len, @NotNull @NotNull ClientSocketMonitorCommand monitor) Writes a packet. The packet contents must not change until this function has returned.This function may be called even if the socket has been closed. In this case he packet is discarded.
- Parameters:
buf- the packet to sendlen- the number of bytes to sendmonitor- the monitor command to send to script processes
-