net.clackrouter.application
Class UDPSocket

java.lang.Object
  extended by net.clackrouter.application.UDPSocket

public class UDPSocket
extends java.lang.Object

A socket implementing the UDP protocol for a Clack application.

Unlike a TCPSocket, a UDPSocket is not a ClackComponent and simple receives datagrams via the addDatagramToQueue(VNSUDPPacket) method and sends datagrams by directly accessing the UDP component.


Nested Class Summary
static class UDPSocket.HostInfo
          Simple structure to tell the source address and port of a received datagram
 
Constructor Summary
UDPSocket(java.lang.String name, UDP parent)
           
 
Method Summary
 void addDatagramToQueue(VNSUDPPacket packet)
           
 void bind()
          Default bind behavior selects a random port in the range between 1024 and 2024 and binds to the first listed interface on the router (often eth0)
 void bind(java.net.InetAddress local_address, int local_port)
          Binds the socket to a specified address and port.
 java.lang.String getName()
          the socket's name
 java.nio.ByteBuffer recvFrom(long msec_timeout, UDPSocket.HostInfo info)
          Receive a UDP datagram
 void sendTo(java.nio.ByteBuffer buf, UDPSocket.HostInfo info)
          Send a datagram to the specified address and port
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UDPSocket

public UDPSocket(java.lang.String name,
                 UDP parent)
Method Detail

addDatagramToQueue

public void addDatagramToQueue(VNSUDPPacket packet)

sendTo

public void sendTo(java.nio.ByteBuffer buf,
                   UDPSocket.HostInfo info)
Send a datagram to the specified address and port

Parameters:
buf - data to be sent
info - destination address and port information

bind

public void bind()
          throws java.lang.Exception
Default bind behavior selects a random port in the range between 1024 and 2024 and binds to the first listed interface on the router (often eth0)

Throws:
java.lang.Exception

bind

public void bind(java.net.InetAddress local_address,
                 int local_port)
          throws java.lang.Exception
Binds the socket to a specified address and port.

At this time, no restrictions are placed on what addresses or ports may be bound to.

Parameters:
local_address - address to bind as source
local_port - port to bind as source
Throws:
java.lang.Exception

recvFrom

public java.nio.ByteBuffer recvFrom(long msec_timeout,
                                    UDPSocket.HostInfo info)
Receive a UDP datagram

Parameters:
msec_timeout - number of milliseconds before the call returns
info - upon return, contains information about datagram source address and port
Returns:
buffer of data, or an empty buffer if timeout

getName

public java.lang.String getName()
the socket's name