megamek.common.net
Interface IConnection

All Known Implementing Classes:
AbstractConnection, DataStreamConnection, ObjectStreamConnection

public interface IConnection

interface for connections between client and server refactored from the original Connection class which was moved to AbstractConnection


Method Summary
 void addConnectionListener(ConnectionListener listener)
          Adds the specified connection listener to receive connection events from connection.
 long bytesReceived()
          Returns a very approximate count of how many bytes were received
 long bytesSent()
          Returns a very approximate count of how many bytes were sent
 void close()
          Closes the socket and releases resources
 void flush()
          sibling of the update() method. will not read anything, will just flush the pending packets from the queue
 int getId()
          Returns the connection ID
 java.lang.String getInetAddress()
           
 boolean hasPending()
          Returns true if there are (send)pending packets
 boolean open()
          Opens the connection
 void removeConnectionListener(ConnectionListener listener)
          Removes the specified connection listener.
 void send(Packet packet)
          Adds a packet to the send queue to be send on a seperate thread.
 void setId(int id)
          Sets the connection ID
 long update()
          call this to update the connection state. should be called a few times per second normally.
 

Method Detail

open

boolean open()
Opens the connection

Returns:
true on success, false otherwise

close

void close()
Closes the socket and releases resources


getId

int getId()
Returns the connection ID

Returns:
the connection ID

setId

void setId(int id)
Sets the connection ID

Parameters:
id - new connection ID Be careful with this... used by server only. cannot be moved to constructor,so should be moved to a separate interface

getInetAddress

java.lang.String getInetAddress()
Returns:
what?

update

long update()
call this to update the connection state. should be called a few times per second normally. This method should not block for too long. Instead it should return 0 and hope to be called asap again.

Returns:
the amount of milliseconds it is approximately ok not to call this method. Must return >=0

flush

void flush()
sibling of the update() method. will not read anything, will just flush the pending packets from the queue


send

void send(Packet packet)
Adds a packet to the send queue to be send on a seperate thread.


hasPending

boolean hasPending()
Returns true if there are (send)pending packets

Returns:
true if there are pending packets

bytesSent

long bytesSent()
Returns a very approximate count of how many bytes were sent

Returns:
a very approximate count of how many bytes were sent

bytesReceived

long bytesReceived()
Returns a very approximate count of how many bytes were received

Returns:
a very approximate count of how many bytes were received

addConnectionListener

void addConnectionListener(ConnectionListener listener)
Adds the specified connection listener to receive connection events from connection.

Parameters:
listener - the connection listener.

removeConnectionListener

void removeConnectionListener(ConnectionListener listener)
Removes the specified connection listener.

Parameters:
listener - the connection listener.