megamek.common.net
Class DataStreamConnection

java.lang.Object
  extended by megamek.common.net.AbstractConnection
      extended by megamek.common.net.DataStreamConnection
All Implemented Interfaces:
IConnection

 class DataStreamConnection
extends AbstractConnection

Implementation of the Connection that uses the DataInputStream and DataOutputStream to send/receive data.


Nested Class Summary
 
Nested classes/interfaces inherited from class megamek.common.net.AbstractConnection
AbstractConnection.INetworkPacket, AbstractConnection.SendQueue
 
Field Summary
protected  int encoding
           
protected  int len
           
protected  PacketReadState state
           
protected  boolean zipped
          store data for packet reception statemachine
 
Fields inherited from class megamek.common.net.AbstractConnection
bytesSent, marshaller, marshallingType, zipData
 
Constructor Summary
DataStreamConnection(java.net.Socket socket, int id)
          Creates new server connection
DataStreamConnection(java.lang.String host, int port, int id)
          Creates new Client connection
 
Method Summary
 void flush()
          override flush to flush the datastream after flushing packetqueue
protected  AbstractConnection.INetworkPacket readNetworkPacket()
          Reads a complete NetworkPacket must not block, must return null instead
protected  void sendNetworkPacket(byte[] data, boolean iszipped)
          Sends the data must not block for too long
 
Methods inherited from class megamek.common.net.AbstractConnection
addConnectionListener, bytesReceived, bytesSent, close, doFlush, getConnectionTypeAbbrevation, getId, getInetAddress, getInputStream, getMarshallingType, getOutputStream, hasPending, isCompressed, isServer, open, processConnectionEvent, processPacket, processPacket, removeConnectionListener, reportLastCommands, reportLastCommands, reportReceiveException, reportReceiveException, reportSendException, send, sendNow, setCompression, setId, setMarshallingType, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

zipped

protected boolean zipped
store data for packet reception statemachine


encoding

protected int encoding

len

protected int len

state

protected PacketReadState state
Constructor Detail

DataStreamConnection

public DataStreamConnection(java.net.Socket socket,
                            int id)
Creates new server connection

Parameters:
socket -
id -

DataStreamConnection

public DataStreamConnection(java.lang.String host,
                            int port,
                            int id)
Creates new Client connection

Parameters:
host -
port -
id -
Method Detail

readNetworkPacket

protected AbstractConnection.INetworkPacket readNetworkPacket()
                                                       throws java.lang.Exception
Description copied from class: AbstractConnection
Reads a complete NetworkPacket must not block, must return null instead

Specified by:
readNetworkPacket in class AbstractConnection
Returns:
the NetworkPacket that was sent.
Throws:
java.lang.Exception

sendNetworkPacket

protected void sendNetworkPacket(byte[] data,
                                 boolean iszipped)
                          throws java.lang.Exception
Description copied from class: AbstractConnection
Sends the data must not block for too long

Specified by:
sendNetworkPacket in class AbstractConnection
Parameters:
data - data to send
iszipped - should the data be compressed
Throws:
java.lang.Exception

flush

public void flush()
override flush to flush the datastream after flushing packetqueue

Specified by:
flush in interface IConnection
Overrides:
flush in class AbstractConnection