|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsimnet.DatagramSocket
The Simnet implementation of a UDP Socket.
| Field Summary | |
protected boolean |
closed
If this socket has been closed |
(package private) java.lang.Object |
consumer
The object that will be calling recv on us (usually an Application) |
static int |
CONSUMER_ID
The notification code when the consumer gets plugged out (randomly chosen to avoid conflicts) |
static int |
DEFAULT_QUEUE_SIZE
The default size of the queue (0 = infinite) |
protected int |
ip
This ip this socket is connected to, -1 for unconnected socket |
protected int |
local_port
The local port this this socket is bound to, -1 if not bound |
protected int |
port
This port this socket is connected to, -1 for unconnected socket |
protected int |
q_size
The maximum permitted size of the queue |
protected int |
q_used
The current size of the rxQueue |
protected java.util.LinkedList |
queue
The linked list of DatagramPackets that were received |
protected Simulator |
sim
A reference to the simulator |
protected long |
timeout
The timeout for receiving packets, in ms (0=infinite) |
(package private) UDP |
udp
The UDP transport we are using |
(package private) UDPStatistics |
us
The statistics for this socket |
| Constructor Summary | |
(package private) |
DatagramSocket(UDP udp,
java.lang.Object consumer)
Create a new socket using the specified udp implementation. |
| Method Summary | |
int |
available()
How many objects are available for immediate reading. |
void |
bind(int port)
Bind this socket to the specified port. |
void |
close()
Close this socket (closed sockets may not be used again). |
void |
connect(int ip,
int port)
Connects this socket to the specified ip and port. |
void |
disconnect()
Turns this socket into an unconnected socket (removes remote binding). |
void |
finalize()
|
int |
getLocalPort()
Returns the local port that this socket is bound to, or -1 if this socket is not bound. |
(package private) void |
in(DatagramPacket p)
Called by udp when it receives a packet for the port this socket is bound to. |
boolean |
isBound()
Returns whether or not this socket is bound. |
boolean |
isClosed()
Returns whether or not this socket is closed. |
boolean |
isConnected()
Returns whether or not this socket is connected. |
void |
plugoutNotification(int id,
java.lang.Object replacement,
java.lang.Object[] args)
When the consumer is getting plugged out, close this socket (or transfer to our replacement). |
java.lang.Object |
recv()
Wait for an object to be received on this socket, can only be used on connected sockets. |
DatagramPacket |
recvfrom()
Receives a datagram from this socket. |
boolean |
send(java.lang.Object data)
Send the given object on this socket, can only be used on connected sockets. |
boolean |
sendto(int dest,
int dest_port,
java.lang.Object data)
Send the given data to the specified destination. |
void |
setTimeout(long timeout)
Set the receive timeout for this socket to be the specified value (0=infinite) |
java.lang.String |
toString()
Returns a string representation of this DatagramSocket |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int CONSUMER_ID
public static final int DEFAULT_QUEUE_SIZE
protected int local_port
protected int ip
protected int port
protected java.util.LinkedList queue
protected int q_size
protected int q_used
protected long timeout
protected boolean closed
UDP udp
java.lang.Object consumer
UDPStatistics us
protected Simulator sim
| Constructor Detail |
DatagramSocket(UDP udp,
java.lang.Object consumer)
| Method Detail |
public void setTimeout(long timeout)
throws SimnetSocketException
SimnetSocketException - if the timeout is negative
public void bind(int port)
throws SimnetSocketException
port - The port number to bind to
SimnetSocketException - if this socket is already bound, is an invalid port
or the port is already in use.public void close()
public void connect(int ip,
int port)
throws SimnetSocketException
SimnetSocketException - if the port is not postive, or this socket
is already connected.public void disconnect()
public boolean send(java.lang.Object data)
throws SimnetSocketException
data - the object to send
SimnetSocketException - if this socket is not connected.
public java.lang.Object recv()
throws SimnetSocketException,
java.lang.InterruptedException
SimnetSocketException - if this socket is not connected.
java.lang.InterruptedException - if this thread is interrupted.
public boolean sendto(int dest,
int dest_port,
java.lang.Object data)
throws SimnetSocketException
dest - the destination ip addressdest_port - the destination portdata - the outgoing data
SimnetSocketException - if this socket is connected
public DatagramPacket recvfrom()
throws SimnetSocketException,
java.lang.InterruptedException
SimnetSocketException - if the socket is not bound, the socket is closed while
waiting for a packet, or the timeout expired
java.lang.InterruptedException - if this thread is interrupted.public int available()
void in(DatagramPacket p)
p - the packet receivedpublic boolean isConnected()
public boolean isBound()
public int getLocalPort()
public boolean isClosed()
public java.lang.String toString()
public void plugoutNotification(int id,
java.lang.Object replacement,
java.lang.Object[] args)
plugoutNotification in interface PlugoutListenerid - The id passed to registerPlugoutNotificationreplacement - the object that will be replacing the object that
is being plugged out. It will be null if the object is getting plugged out,
rather then being replaced with a new plugin.args - were the args passed to registerPlugoutNotificationpublic void finalize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||