org.xsocket.datagram
Interface IEndpoint

Package class diagram package IEndpoint
All Superinterfaces:
java.io.Closeable
All Known Subinterfaces:
IConnectedEndpoint
All Known Implementing Classes:
ConnectedEndpoint, Endpoint, MulticastEndpoint

public interface IEndpoint
extends java.io.Closeable

An endpoint, which can be used to send and receive UserDatagram. E.g.


  // without datagram handler
  ...
  IEndpoint endpoint = new Endpoint(packageSize);

  UserDatagram request = new UserDatagram(remoteHostname, remotePort, packageSize);
  request.write("Hello peer, how are you?");

  endpoint.send(request);
  UserDatagram response = endpoint.receive(1000);  // receive (timeout 1 sec)

  endpoint.close();
  ...


  // by using a handler
  ...
  MyHandler hdl = new MyHandler();
  IEndpoint endpoint = new Endpoint(packageSize, hdl);

  UserDatagram request = new UserDatagram(remoteHostname, remotePort, packageSize);
  request.write("Hello peer, how are you?");

  endpoint.send(request);
  // response will be handled by MyHandler

  // wait
  ...
  endpoint.close();


  class MyHandler implements IDatagramHandler {

     public boolean onDatagram(IEndpoint localEndpoint) throws IOException {
          UserDatagram datagram = localEndpoint.receive();  // get the datagram
          ...
          return true;
     }
  }
 


Field Summary
static java.lang.String DEFAULT_HOST_ADDRESS
          the default host address
static java.lang.String IP_MULTICAST_LOOP
           
static java.lang.String IP_MULTICAST_TTL
           
static java.lang.String IP_TOS
           
static java.lang.String SO_BROADCAST
           
static java.lang.String SO_RCVBUF
           
static java.lang.String SO_REUSEADDR
           
static java.lang.String SO_SNDBUF
           
 
Method Summary
 java.lang.String getDefaultEncoding()
          gets the default encoding used by this endpoint
 java.lang.String getId()
          return the endpoint id
 java.net.InetAddress getLocalAddress()
          returns the address of the endpoint
 int getLocalPort()
          returns the port of the endpoint
 java.net.SocketAddress getLocalSocketAddress()
          Deprecated.  
 java.lang.Object getOption(java.lang.String name)
          returns the vlaue of a option
 java.util.Map<java.lang.String,java.lang.Class> getOptions()
          Returns an unmodifiable map of the options supported by this endpont.
 int getReceiveSize()
          get the size of the datagram that will be received
 boolean isOpen()
          returns, if the endpoint is open
 UserDatagram receive()
          receive a datagram packet (receive timeout = 0)
 UserDatagram receive(long timeoutMillis)
          receive a datagram packet
 void send(UserDatagram datagram)
          send a datagram to the remote endpoint
 void setDefaultEncoding(java.lang.String encoding)
          sets the default encoding used by this endpoint
 void setReceiveSize(int receiveSize)
          set the size of the datagram that will be received
 void setWorkerPool(IWorkerPool workerPool)
          Deprecated.  
 
Methods inherited from interface java.io.Closeable
close
 

Field Detail

SO_SNDBUF

static final java.lang.String SO_SNDBUF
See Also:
Constant Field Values

SO_RCVBUF

static final java.lang.String SO_RCVBUF
See Also:
Constant Field Values

SO_REUSEADDR

static final java.lang.String SO_REUSEADDR
See Also:
Constant Field Values

SO_BROADCAST

static final java.lang.String SO_BROADCAST
See Also:
Constant Field Values

IP_TOS

static final java.lang.String IP_TOS
See Also:
Constant Field Values

IP_MULTICAST_TTL

static final java.lang.String IP_MULTICAST_TTL
See Also:
Constant Field Values

IP_MULTICAST_LOOP

static final java.lang.String IP_MULTICAST_LOOP
See Also:
Constant Field Values

DEFAULT_HOST_ADDRESS

static final java.lang.String DEFAULT_HOST_ADDRESS
the default host address

See Also:
Constant Field Values
Method Detail

isOpen

boolean isOpen()
returns, if the endpoint is open

Returns:
true if the endpoint is open

getLocalSocketAddress

java.net.SocketAddress getLocalSocketAddress()
Deprecated. 


getLocalAddress

java.net.InetAddress getLocalAddress()
returns the address of the endpoint

Returns:
the address

getLocalPort

int getLocalPort()
returns the port of the endpoint

Returns:
the port

setDefaultEncoding

void setDefaultEncoding(java.lang.String encoding)
sets the default encoding used by this endpoint

Parameters:
encoding - the default encoding

getDefaultEncoding

java.lang.String getDefaultEncoding()
gets the default encoding used by this endpoint

Returns:
the default encoding

send

void send(UserDatagram datagram)
          throws java.io.IOException
send a datagram to the remote endpoint

Parameters:
datagram - the datagram to send
Throws:
java.io.IOException - If some other I/O error occurs
ClosedConnectionException - if the underlying channel is closed

setReceiveSize

void setReceiveSize(int receiveSize)
set the size of the datagram that will be received

Parameters:
receiveSize - the receive size

getReceiveSize

int getReceiveSize()
get the size of the datagram that will be received

Returns:
the receive size

receive

UserDatagram receive()
                     throws java.io.IOException
receive a datagram packet (receive timeout = 0)

Returns:
the received datagram packet or null if no datagram is available
Throws:
java.io.IOException - If some other I/O error occurs

receive

UserDatagram receive(long timeoutMillis)
                     throws java.io.IOException,
                            java.net.SocketTimeoutException
receive a datagram packet

Parameters:
timeoutMillis - the receive timeout in millis
Returns:
the received datagram packet
Throws:
java.net.SocketTimeoutException - If the receive timeout has been reached
java.io.IOException - If some other I/O error occurs

setWorkerPool

void setWorkerPool(IWorkerPool workerPool)
Deprecated. 


getId

java.lang.String getId()
return the endpoint id

Returns:
the endpoint id

getOption

java.lang.Object getOption(java.lang.String name)
                           throws java.io.IOException
returns the vlaue of a option

Parameters:
name - the name of the option
Returns:
the value of the option
Throws:
java.io.IOException - In an I/O error occurs

getOptions

java.util.Map<java.lang.String,java.lang.Class> getOptions()
Returns an unmodifiable map of the options supported by this endpont. The key in the returned map is the name of a option, and its value is the type of the option value. The returned map will never contain null keys or values.

Returns:
An unmodifiable map of the options supported by this channel