p2ps.imp.endpoint.UDP
Class UDPEndpoint

java.lang.Object
  extended byp2ps.imp.endpoint.UDP.UDPEndpoint
All Implemented Interfaces:
Endpoint, UDPEndpointSchemes
Direct Known Subclasses:
UDPMulticastEndpoint, UDPOutputEndpoint

public class UDPEndpoint
extends java.lang.Object
implements Endpoint, UDPEndpointSchemes

A class that sends and receives message bytes to/from a Datagram Socket. If the message bytes exceed the packet size the message is split into multiple packets.

Version:
$Revision: 295 $
Author:
Ian Wang

Nested Class Summary
static class UDPEndpoint.DefaultInputMonitorFactory
           
 
Field Summary
static int MAX_DATAGRAM_SIZE
           
static InputMonitorFactory monfactory
          the input monitor factory
static int RECEIVE_BUFFER_SIZE
           
static int SEND_BUFFER_SIZE
           
protected  DatagramSocket socket
          the socket data is sent to
static int SOCKET_TIMEOUT
           
 
Fields inherited from interface p2ps.imp.endpoint.UDP.UDPEndpointSchemes
UDP_MULTICAST, UDP_STANDARD
 
Constructor Summary
  UDPEndpoint(boolean input)
          Creates a standard UDP socket for an available port
  UDPEndpoint(int port)
          Creates a standard UDP socket for the specified port
protected UDPEndpoint(java.lang.String scheme, int port, boolean input)
           
protected UDPEndpoint(UDPEndpoint udpsocket)
          Creates a UDP socket based on an already existing socket
 
Method Summary
 void addEndpointMessageListener(EndpointMessageListener listener)
          Adds a listener to receive data from this endpoint
 void close()
          Closes the socket
 java.net.URI getEndpointURI()
           
 java.net.URI getSendURI()
           
 DatagramSocket getSocket()
           
 void handleMessage(DataMessage message, java.net.SocketAddress replyaddr)
          Called by a single input endpoint when a message is received.
 void init()
          Initializes the socket
protected  void initSocket(int port, boolean input)
          Initialises the socket
 boolean isClosed()
           
 boolean isInputEndpoint()
           
 boolean isOutputEndpoint()
           
 void removeEndpointMessageListener(EndpointMessageListener listener)
          Removes a listener from this endpoint
 void send(byte[] message)
          Sends a message from the endpoint to the address the endpoint is bound to, with no sendid.
 void send(java.lang.String sendid, byte[] message)
          Sends a message from the endpoint to the address the endpoint is bound to, along with the send id for this message.
 void send(java.lang.String sendid, byte[] message, java.net.SocketAddress addr)
          Sends a message from the socket to the specified address
 void send(java.lang.String sendid, byte[] message, java.net.URI uri)
          Sends a message from the socket to the specified address
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_DATAGRAM_SIZE

public static int MAX_DATAGRAM_SIZE

SEND_BUFFER_SIZE

public static int SEND_BUFFER_SIZE

RECEIVE_BUFFER_SIZE

public static int RECEIVE_BUFFER_SIZE

SOCKET_TIMEOUT

public static int SOCKET_TIMEOUT

monfactory

public static InputMonitorFactory monfactory
the input monitor factory


socket

protected DatagramSocket socket
the socket data is sent to

Constructor Detail

UDPEndpoint

public UDPEndpoint(boolean input)
            throws java.io.IOException
Creates a standard UDP socket for an available port


UDPEndpoint

public UDPEndpoint(int port)
            throws java.io.IOException
Creates a standard UDP socket for the specified port


UDPEndpoint

protected UDPEndpoint(java.lang.String scheme,
                      int port,
                      boolean input)
               throws java.io.IOException

UDPEndpoint

protected UDPEndpoint(UDPEndpoint udpsocket)
Creates a UDP socket based on an already existing socket

Method Detail

initSocket

protected void initSocket(int port,
                          boolean input)
                   throws java.io.IOException
Initialises the socket

Throws:
java.io.IOException

init

public void init()
Initializes the socket

Specified by:
init in interface Endpoint

addEndpointMessageListener

public void addEndpointMessageListener(EndpointMessageListener listener)
Adds a listener to receive data from this endpoint

Specified by:
addEndpointMessageListener in interface Endpoint

removeEndpointMessageListener

public void removeEndpointMessageListener(EndpointMessageListener listener)
Removes a listener from this endpoint

Specified by:
removeEndpointMessageListener in interface Endpoint

getSocket

public DatagramSocket getSocket()
Returns:
the datagram socket for this udp socket

getEndpointURI

public java.net.URI getEndpointURI()
Specified by:
getEndpointURI in interface Endpoint
Returns:
the transport protocol for this socket

getSendURI

public java.net.URI getSendURI()
Specified by:
getSendURI in interface Endpoint
Returns:
the address being sent to by this endpoint (if known)

isInputEndpoint

public boolean isInputEndpoint()
Specified by:
isInputEndpoint in interface Endpoint
Returns:
true if this endpoint is input enabled

isOutputEndpoint

public boolean isOutputEndpoint()
Specified by:
isOutputEndpoint in interface Endpoint
Returns:
true if this endpoint is output enabled

send

public void send(byte[] message)
          throws java.io.IOException
Sends a message from the endpoint to the address the endpoint is bound to, with no sendid.

Specified by:
send in interface Endpoint
Throws:
java.io.IOException

send

public void send(java.lang.String sendid,
                 byte[] message)
          throws java.io.IOException
Sends a message from the endpoint to the address the endpoint is bound to, along with the send id for this message.

Specified by:
send in interface Endpoint
Throws:
java.io.IOException

send

public void send(java.lang.String sendid,
                 byte[] message,
                 java.net.URI uri)
          throws java.io.IOException
Sends a message from the socket to the specified address

Throws:
java.io.IOException

send

public void send(java.lang.String sendid,
                 byte[] message,
                 java.net.SocketAddress addr)
          throws java.io.IOException
Sends a message from the socket to the specified address

Throws:
java.io.IOException

handleMessage

public void handleMessage(DataMessage message,
                          java.net.SocketAddress replyaddr)
Called by a single input endpoint when a message is received. The input endpoint notifies all the data message listeners


close

public void close()
           throws java.io.IOException
Closes the socket

Specified by:
close in interface Endpoint
Throws:
java.io.IOException

isClosed

public boolean isClosed()
Specified by:
isClosed in interface Endpoint
Returns:
true is the socket is closed