SSF.OS.UDP
Class udpSocket

java.lang.Object
  |
  +--SSF.OS.UDP.udpSocket
All Implemented Interfaces:
socketAPI

public class udpSocket
extends java.lang.Object
implements socketAPI

The four socket variables: local_ip, remote_ip, local_port, remote_port identify an end2end UDP session, if at least the local_port, remote_ip and remote_port have valid values. Else if only local_port (and optionally local_ip) are valid, while remote_ip = remote_port = -1, this is a local 'listening server' socket.

The socket variables last_remote_ip, last_remote_port, last_local_ip store the source and destination of the last received UDP/IP header if this is a 'listening server socket', and they can be retrieved by the application that opened this socket.

UDP has no flow control, therefore for a UDP socket the write() operation sends nbytes of data (virtual or an object) immediately in a single UDP datagram if nbytes <= max_datagram_size set by DML attribute udpinit.max_datagram_size.

The UDP socket write() Continuation returns immediately after the datagram was passed through a chain of push() (or equivalent) methods to UDP, IP, and NIC; with a success() if the datagram was successfuly placed in the NIC output queue, and with the failure() if the datagram was dropped by either UDP (nbytes > max_datagram_size), or IP (no route to remote_ip), or by NIC (output queue overflow). Thus write() blocks only for zero elapsed simulation time.

However, UDP socket read() blocks until it receives the requested nbytes of virtual bytes. The socket owner may request to read an arbitrary number of virtual bytes (greater than max_datagram_size). SSF.OS.UDP application writers should keep in mind that since UDP is unreliable, the read() might block forever.


Field Summary
 ProtocolSession appsess
          local application session that created this socket
 dataMessage emptyMsg
           
 int last_local_ip
           
 int last_remote_ip
           
 int last_remote_port
           
 int local_ip
           
 int local_port
           
 int remote_ip
           
 int remote_port
           
 udpSession udpsess
          local UDP session associated with this socket
 udpSessionMaster udpsessMaster
           
 
Constructor Summary
udpSocket(ProtocolSession caller, socketMaster sm)
          Constructors
 
Method Summary
 void abort()
          not supported for udp sockets
 void accept(socketAPI[] new_socket, Continuation caller)
          not supported for udp sockets
 void bind(int my_ip, int my_port)
          names a local socket.
 void close(Continuation caller)
          Close a connection.
 void connect(int dest_ip, int dest_port, Continuation caller)
          sets remote IP and UDP port number and creates a UDP session so that socket write() may be used to send UDP datagrams - non-blocking.
 void listen(int request_limit)
          after bind(), create a UDP listening session so that read() may be used.
 void messageBuffer(dataMessage msg)
           
 void read(byte[] buf, int nbytes, Continuation caller)
          not supported for udp sockets
 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)
          not supported for udp sockets
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

udpsess

public udpSession udpsess
local UDP session associated with this socket


udpsessMaster

public udpSessionMaster udpsessMaster

appsess

public ProtocolSession appsess
local application session that created this socket


local_ip

public int local_ip

remote_ip

public int remote_ip

local_port

public int local_port

remote_port

public int remote_port

last_remote_ip

public int last_remote_ip

last_local_ip

public int last_local_ip

last_remote_port

public int last_remote_port

emptyMsg

public dataMessage emptyMsg
Constructor Detail

udpSocket

public udpSocket(ProtocolSession caller,
                 socketMaster sm)
Constructors

Method Detail

bind

public void bind(int my_ip,
                 int my_port)
names a local socket. If local_ip = -1, a valid local host interface address will be assigned by SSF.OS.IP to datagrams sent via this socket after a UDP session is created via listen() or connect().

Specified by:
bind in interface socketAPI
Parameters:
my_ip - local IP address
my_port - local port number

listen

public void listen(int request_limit)
after bind(), create a UDP listening session so that read() may be used. request_limit is not implemented.

Specified by:
listen in interface socketAPI
Parameters:
request_limit - For tcpSocket, specifies the maximum number of connection requests pending accept. Ignored by udpSocket.

connect

public void connect(int dest_ip,
                    int dest_port,
                    Continuation caller)
             throws ProtocolException
sets remote IP and UDP port number and creates a UDP session so that socket write() may be used to send UDP datagrams - non-blocking.

Specified by:
connect in interface socketAPI
Parameters:
dest_ip - remote IP address
dest_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)
not supported for udp sockets

Specified by:
accept in interface socketAPI
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.

write

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

Specified by:
write in interface socketAPI
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)
not supported for udp sockets

Specified by:
write in interface socketAPI
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)
Description copied from interface: socketAPI
Write simulated pseudo-data to the socket.

Specified by:
write in interface socketAPI
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)
not supported for udp sockets

Specified by:
read in interface socketAPI
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.

abort

public void abort()
not supported for udp sockets

Specified by:
abort in interface socketAPI

read

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

Specified by:
read in interface socketAPI
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)
Description copied from interface: socketAPI
Read pseudo-data received by the socket.

Specified by:
read in interface socketAPI
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.

close

public void close(Continuation caller)
           throws ProtocolException
Description copied from interface: socketAPI
Close a connection.

Specified by:
close in interface socketAPI
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

messageBuffer

public void messageBuffer(dataMessage msg)