SSF.OS.Socket
Interface socketAPI

All Known Implementing Classes:
tcpSocket, udpSocket

public interface socketAPI


Method Summary
 void abort()
          Abort a connection.
 void accept(socketAPI[] new_socket, Continuation caller)
          For TCP, accept an established connection (after three-way handshake) from the pending connection request queue.
 void bind(int local_ip, int local_port)
          Bind the local IP address and port number to the socket.
 void close(Continuation caller)
          Close a connection.
 void connect(int remote_ip, int remote_port, Continuation caller)
          For TCP, active open a connection to a remote host (blocking).
 void listen(int queue_limit)
          Set up the socket to accept incoming connection requests (TCP) or incoming datagrams (UDP) on the port bound to the socket.
 void read(byte[] buf, int nbytes, Continuation caller)
          Read the data received by socket and write them into user-defined byte array.
 void read(int nbytes, Continuation caller)
          Read pseudo-data received by the socket.
 void read(java.lang.Object[] obj, int nbytes, Continuation caller)
          Read a data object received by the socket.
 void write(byte[] buf, int nbytes, Continuation caller)
          Write data from a byte array to the socket.
 void write(int nbytes, Continuation caller)
          Write simulated pseudo-data to the socket.
 void write(java.lang.Object[] obj, int nbytes, Continuation caller)
          Write a concrete data object to the socket.
 

Method Detail

bind

public void bind(int local_ip,
                 int local_port)
Bind the local IP address and port number to the socket.

Parameters:
local_ip - local IP address
local_port - local port number

listen

public void listen(int queue_limit)
Set up the socket to accept incoming connection requests (TCP) or incoming datagrams (UDP) on the port bound to the socket. Creates an instance of tcpSession or udpSession in passive open state and binds it to the socket.

Parameters:
queue_limit - For tcpSocket, specifies the maximum number of connection requests pending accept. Ignored by udpSocket.

connect

public void connect(int remote_ip,
                    int remote_port,
                    Continuation caller)
             throws ProtocolException
For TCP, active open a connection to a remote host (blocking).

For UDP, set up a UDP session for writing (non-blocking).

Parameters:
remote_ip - remote IP address
remote_port - remote port number
caller - user-defined Continuation specifying the actions to be taken when a connection is either successfully established or an error is signalled.
ProtocolException

accept

public void accept(socketAPI[] new_socket,
                   Continuation caller)
            throws ProtocolException
For TCP, accept an established connection (after three-way handshake) from the pending connection request queue. Blocking if there are no pending established connection requests.

Do not use with UDP sockets.

Parameters:
new_socket - one-element array that will contain the new connected socket when Continuation returns successfully.
caller - user-defined Continuation specifying the actions to be taken when a connection is either successfully accepted or an error is signalled.
ProtocolException

write

public void write(java.lang.Object[] obj,
                  int nbytes,
                  Continuation caller)
Write a concrete data object to the socket.

Parameters:
obj - user-defined array whose first element obj[0] will be sent
nbytes - nominal size (in bytes) of the data object that defines the transmitted payload size
caller - user-defined Continuation specifying the actions to be taken when either nbytes of (virtual) data is successfully written or an error is signalled.

write

public void write(byte[] buf,
                  int nbytes,
                  Continuation caller)
Write data from a byte array to the socket.

Parameters:
nbytes - size of data to be transmitted
caller - user-defined Continuation specifying the actions to be taken when either nbytes of data is successfully written or an error is signalled.

write

public void write(int nbytes,
                  Continuation caller)
Write simulated pseudo-data to the socket.

Parameters:
nbytes - number of bytes of pseudo-data that defines the transmitted payload size
caller - user-defined Continuation specifying the actions to be taken when either nbytes of data is successfully written or an error is signalled.

read

public void read(byte[] buf,
                 int nbytes,
                 Continuation caller)
Read the data received by socket and write them into user-defined byte array. Blocks until nbytes of data is received or an error is signalled.

Parameters:
nbytes - expected received data size
caller - user-defined Continuation specifying the actions to be taken when either all data is read successfully or an error is signalled.

read

public void read(java.lang.Object[] obj,
                 int nbytes,
                 Continuation caller)
Read a data object received by the socket.

Parameters:
obj - user-defined array whose first element obj[0] will contain the data object if read is successful
nbytes - expected number of received data bytes
caller - user-defined Continuation specifying the actions to be taken when either all data is read successfully or an error is signalled.

read

public void read(int nbytes,
                 Continuation caller)
Read pseudo-data received by the socket.

Parameters:
nbytes - expected number of bytes of received pseudo-data
caller - user-defined Continuation specifying the actions to be taken when either all data is read successfully or an error is signalled.

abort

public void abort()
Abort a connection. For TCP, will cause a RESET to be sent.


close

public void close(Continuation caller)
           throws ProtocolException
Close a connection.

Parameters:
caller - the user defined Continuation class which defines the action should be taken when connection is either successfully closed or an error is signalled.
ProtocolException