jAER project on SourceForge

net.sf.jaer.eventio
Class AESocket

java.lang.Object
  extended by net.sf.jaer.eventio.AESocket

public class AESocket
extends java.lang.Object

Streams in or out packets of events from or to a stream socket network connection over a reliable TCP connection.

Stream format is very simple:

 int32 address0
 int32 timestamp0
 int32 address1
 int32 timestamp1
 etc for n AEs.
 
The timestamp tick is us. The addresses are raw device addresses. See the AEChip classes for their EventExtractor2D inner class extractor definitions for individual device address formats.

Author:
tobi

Nested Class Summary
 class AESocket.NonMonotonicTimeException
          class used to signal a backwards read from input stream
 class AESocket.WrappedTimeException
           
 
Field Summary
static int CONNECTION_TIMEOUT_MS
          timeout in ms for connection attempts
static int DEFAULT_BUFFERED_STREAM_SIZE_BYTES
           
static int DEFAULT_RECEIVE_BUFFER_SIZE_BYTES
           
static int DEFAULT_SEND_BUFFER_SIZE_BYTES
           
 int MAX_NONMONOTONIC_TIME_EXCEPTIONS_TO_PRINT
           
static int MAX_PACKET_SIZE_EVENTS
           
static int SO_TIMEOUT
          timeout in ms for read/write attempts
 
Constructor Summary
AESocket()
           
AESocket(java.net.Socket s)
          Creates a new instance of AESocket using an existing Socket.
AESocket(java.lang.String host, int port)
          Creates a new instance of AESocket for connection to the host:port.
 
Method Summary
 void close()
          Closes the AESocket and nulls the data input and output streams
 void connect()
          Connects to the socket, using the specified host and port specified in the constructor
 int getBufferedStreamSize()
           
 java.lang.String getHost()
           
static java.lang.String getLastHost()
           
 int getMostRecentTimestamp()
           
 int getPort()
           
 int getReceiveBufferSize()
           
 int getSendBufferSize()
           
 java.net.Socket getSocket()
          returns the underlying Socket
 boolean isConnected()
          Is this socket connected.
 boolean isFlushPackets()
           
 boolean isUseBufferedStreams()
           
 AEPacketRaw readPacket()
          returns events from AESocket.
 void setBufferedStreamSize(int sizeBytes)
           
 void setFlushPackets(boolean flushPackets)
           
 void setHost(java.lang.String host)
          Sets the preferred host:port string.
 void setMostRecentTimestamp(int mostRecentTimestamp)
           
 void setPort(int port)
           
 void setReceiveBufferSize(int sizeBytes)
           
 void setSendBufferSize(int sizeBytes)
           
 void setUseBufferedStreams(boolean useBufferedStreams)
           
 java.lang.String toString()
           
 void writePacket(AEPacketRaw p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_RECEIVE_BUFFER_SIZE_BYTES

public static final int DEFAULT_RECEIVE_BUFFER_SIZE_BYTES
See Also:
Constant Field Values

DEFAULT_SEND_BUFFER_SIZE_BYTES

public static final int DEFAULT_SEND_BUFFER_SIZE_BYTES
See Also:
Constant Field Values

DEFAULT_BUFFERED_STREAM_SIZE_BYTES

public static final int DEFAULT_BUFFERED_STREAM_SIZE_BYTES
See Also:
Constant Field Values

CONNECTION_TIMEOUT_MS

public static final int CONNECTION_TIMEOUT_MS
timeout in ms for connection attempts

See Also:
Constant Field Values

SO_TIMEOUT

public static final int SO_TIMEOUT
timeout in ms for read/write attempts

See Also:
Constant Field Values

MAX_NONMONOTONIC_TIME_EXCEPTIONS_TO_PRINT

public final int MAX_NONMONOTONIC_TIME_EXCEPTIONS_TO_PRINT
See Also:
Constant Field Values

MAX_PACKET_SIZE_EVENTS

public static final int MAX_PACKET_SIZE_EVENTS
See Also:
Constant Field Values
Constructor Detail

AESocket

public AESocket(java.net.Socket s)
         throws java.io.IOException
Creates a new instance of AESocket using an existing Socket.

Parameters:
s - the socket to use.
Throws:
java.io.IOException

AESocket

public AESocket(java.lang.String host,
                int port)
Creates a new instance of AESocket for connection to the host:port. Before calling connect(), options can be set on the socket like the buffer size.

Parameters:
host - to connect to. Can have format host:port. If port is omitted, it defaults to AENetworkInterface.PORT.
See Also:
connect()

AESocket

public AESocket()
Method Detail

setReceiveBufferSize

public void setReceiveBufferSize(int sizeBytes)

setSendBufferSize

public void setSendBufferSize(int sizeBytes)

setBufferedStreamSize

public void setBufferedStreamSize(int sizeBytes)

getReceiveBufferSize

public int getReceiveBufferSize()

getSendBufferSize

public int getSendBufferSize()

getBufferedStreamSize

public int getBufferedStreamSize()

readPacket

public AEPacketRaw readPacket()
                       throws java.io.IOException
returns events from AESocket. An IOException closes the socket. A timeout just return the whatever events have been received. An EOF exception returns events that have been recieved.

Returns:
the read packet
Throws:
java.io.IOException

writePacket

public void writePacket(AEPacketRaw p)
                 throws java.io.IOException
Throws:
java.io.IOException

getMostRecentTimestamp

public int getMostRecentTimestamp()
Returns:
returns the most recent timestamp

setMostRecentTimestamp

public void setMostRecentTimestamp(int mostRecentTimestamp)

close

public void close()
           throws java.io.IOException
Closes the AESocket and nulls the data input and output streams

Throws:
java.io.IOException

getHost

public java.lang.String getHost()

setHost

public void setHost(java.lang.String host)
Sets the preferred host:port string. Set on sucessful completion of input stream connection.


getPort

public int getPort()

setPort

public void setPort(int port)

getLastHost

public static java.lang.String getLastHost()
Returns:
the last host successfully connected to

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getSocket

public java.net.Socket getSocket()
returns the underlying Socket


connect

public void connect()
             throws java.io.IOException
Connects to the socket, using the specified host and port specified in the constructor

Throws:
java.io.IOException - if underlying socket cannot connect

isUseBufferedStreams

public boolean isUseBufferedStreams()

setUseBufferedStreams

public void setUseBufferedStreams(boolean useBufferedStreams)

isFlushPackets

public boolean isFlushPackets()

setFlushPackets

public void setFlushPackets(boolean flushPackets)

isConnected

public boolean isConnected()
Is this socket connected.

Returns:
false if underlying socket is null or is not connected

jAER project on SourceForge