public class ClientSocket
extends java.lang.Object
final ClientSocket clientSocket = new ClientSocket(...); clientSocket.writePacket(...); clientSocket.disconnect();
| Constructor and Description |
|---|
ClientSocket(@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 be notified. |
void |
connect(@NotNull java.lang.String host,
int port)
Connects to a server.
|
void |
disconnect(@NotNull java.lang.String reason,
boolean isError)
Terminates the connection.
|
void |
removeClientSocketListener(@NotNull ClientSocketListener clientSocketListener)
Removes a
ClientSocketListener to be notified. |
void |
start()
Starts operation.
|
void |
stop()
Stops operation.
|
void |
writePacket(byte[] buf,
int len,
@NotNull ClientSocketMonitorCommand monitor)
Writes a packet.
|
public ClientSocket(@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 the socket cannot be createdpublic void start()
public void stop()
throws java.lang.InterruptedException
java.lang.InterruptedException - if stopping was interruptedpublic void addClientSocketListener(@NotNull
@NotNull ClientSocketListener clientSocketListener)
ClientSocketListener to be notified.clientSocketListener - the client socket listener to addpublic void removeClientSocketListener(@NotNull
@NotNull ClientSocketListener clientSocketListener)
ClientSocketListener to be notified.clientSocketListener - the client socket listener to removepublic void connect(@NotNull
@NotNull java.lang.String host,
int port)
host - the host to connect toport - the port to connect topublic void disconnect(@NotNull
@NotNull java.lang.String reason,
boolean isError)
reason - the reason for the disconnectisError - whether the disconnect is unexpectedpublic void writePacket(byte[] buf,
int len,
@NotNull
@NotNull ClientSocketMonitorCommand monitor)
This function may be called even if the socket has been closed. In this case he packet is discarded.
buf - the packet to sendlen - the number of bytes to sendmonitor - the monitor command to send to script processes