Package megamek.common.net.connections
Class DataStreamConnection
java.lang.Object
megamek.common.net.connections.AbstractConnection
megamek.common.net.connections.DataStreamConnection
Implementation of the AbstractConnection that uses the DataInputStream and DataOutputStream to send/receive data.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected PacketReadStateprotected booleanstore data for packet reception statemachineFields inherited from class megamek.common.net.connections.AbstractConnection
marshaller, marshallingType -
Constructor Summary
ConstructorsConstructorDescriptionDataStreamConnection(String host, int port, int id) Creates new Client connection.DataStreamConnection(Socket socket, int id) Creates new server connection. -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()override flush to flush the data stream after flushing packet queueprotected INetworkPacketReads a complete NetworkPacket.protected voidsendNetworkPacket(byte[] data, boolean isZipped) Sends the data.toString()Methods inherited from class megamek.common.net.connections.AbstractConnection
addConnectionListener, close, getBytesReceived, getBytesSent, getConnectionTypeText, getId, getInetAddress, getInputStream, getMarshallingType, getOutputStream, getReceiveBufferSize, getSendBufferSize, hasPending, isClosed, isCompressed, isServer, open, processConnectionEvent, processPacket, processPacket, removeConnectionListener, send, sendNow, setCompression, setId, setMarshallingType, update
-
Field Details
-
zipped
protected boolean zippedstore data for packet reception statemachine -
encoding
protected int encoding -
len
protected int len -
state
-
-
Constructor Details
-
DataStreamConnection
Creates new server connection.- Parameters:
socket- The network socket to useid- The connection ID
-
DataStreamConnection
Creates new Client connection.- Parameters:
host- The host addressport- The network portid- The connection ID
-
-
Method Details
-
readNetworkPacket
Description copied from class:AbstractConnectionReads a complete NetworkPacket. This method must not block, must return null instead.- Specified by:
readNetworkPacketin classAbstractConnection- Returns:
- the NetworkPacket that was sent.
- Throws:
Exception
-
sendNetworkPacket
Description copied from class:AbstractConnectionSends the data. This must not be blocked for too long- Specified by:
sendNetworkPacketin classAbstractConnection- Parameters:
data- data to sendisZipped- should the data be compressed- Throws:
Exception- if there's an issue with sending the packet
-
flush
public void flush()override flush to flush the data stream after flushing packet queue- Overrides:
flushin classAbstractConnection
-
toString
-