dk.i1.sctp
Class SCTPSocket

java.lang.Object
  extended by dk.i1.sctp.SCTPSocket
Direct Known Subclasses:
OneToManySCTPSocket, OneToOneSCTPSocket

public class SCTPSocket
extends java.lang.Object

An SCTP socket An SCTP socket behaves in some ways like a TCP socket and in some ways like a datagram socket.

You cannot instantiate a SCTPSocket, but rather one of its two subclasses: OneToOneSCTPSocket and OneToManySCTPSocket.


Method Summary
 void bind()
          Bind to an unspecified address/port.
 void bind(java.net.InetAddress addr, int port)
          Deprecated. An important feature of SCTP is multi-homing. This method binds the socket to a single interface and effectively disables multi-homing. This method is only here for completeness' sake.
 void bind(java.net.InetSocketAddress bindaddr)
          Deprecated. An important feature of SCTP is multi-homing. This method binds the socket to a single interface and effectively disables multi-homing. This method is only here for completeness' sake.
 void bind(int port)
          Bind to a specific port.
 boolean chunkAvailable()
          Probe if any unread chunks are pending
 void close()
          Close the socket.
 void configureAutoClose(int seconds)
          Configure the auto-close feature.
 void configureBlocking(boolean block)
          Set the blocking mode.
 void connect(java.net.InetAddress addr, int port)
          Create an association to a peer.
 void connect(java.net.InetSocketAddress addr)
          Create an association to a peer.
 void disconnect(AssociationId assoc_id)
          Shut down an association.
 void disconnect(AssociationId assoc_id, boolean gracefully)
          Shut down an association.
protected  void finalize()
           
 java.util.Collection<java.net.InetAddress> getLocalInetAddresses()
          Get local addressed uses by the socket.
 java.util.Collection<java.net.InetAddress> getLocalInetAddresses(AssociationId assoc_id)
          Get local addresses used by the socket.
 int getLocalInetPort()
          Get local port.
 java.util.Collection<java.net.InetAddress> getPeerInetAddresses(AssociationId assoc_id)
          Get addresses of a peer.
 int getPeerInetPort(AssociationId assoc_id)
           
 int getReceiveBufferSize()
          Get the SO_RCVBUF option for the socket.
 boolean getSctpNoDelay()
          Tests if SCTP_NODELAY is enabled.
 int getSendBufferSize()
          Get the SO_SNDBUF option for the socket.
 boolean isBlocking()
          Tells whether send() and connect() may block.
 boolean isClosed()
          Returns the closed state of the socket.
 void listen()
          Enable inbound connections.
 SCTPChunk receive()
          Receive a data chunk or a notification.
 SCTPChunk receive(long timeout)
          Receive a data chunk or a notification.
 SCTPChunk receiveNow()
          Receive a data chunk or a notification.
 void send(SCTPData sctpdata)
          Send a datagram to a peer.
 void setInitMsg(sctp_initmsg im)
          Set default association parameters.
 void setPeerParameters(sctp_paddrparams spp)
          Set the parameters for a peer.
 void setReceiveBufferSize(int size)
          Sets the SO_RCVBUF option for this socket.
 void setSctpNoDelay(boolean on)
          Enable/disable SCTP_NODELAY (disable/enable Nagle's algorithm).
 void setSendBufferSize(int size)
          Sets the SO_SNDBUF option for this socket.
 void subscribeEvents(sctp_event_subscribe ses)
          Subscribe to specific SCTP notifications.
 void wakeup()
          Wake other threads from receive().
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

bind

public void bind()
          throws java.net.SocketException
Bind to an unspecified address/port. Binds the socket to a system-decided port and set of addresses. A socket can only be bound once.

Throws:
java.net.SocketException

bind

public void bind(int port)
          throws java.net.SocketException
Bind to a specific port. Binds the socket to the specified port, and system-decided set of addresses. A socket can only be bound once.

Parameters:
port - the SCTP port to bind to.
Throws:
java.net.SocketException

bind

public void bind(java.net.InetSocketAddress bindaddr)
          throws java.net.SocketException
Deprecated. An important feature of SCTP is multi-homing. This method binds the socket to a single interface and effectively disables multi-homing. This method is only here for completeness' sake.

Bind to a specific socket address. A socket can only be bound once.

Throws:
java.net.SocketException

bind

public void bind(java.net.InetAddress addr,
                 int port)
          throws java.net.SocketException
Deprecated. An important feature of SCTP is multi-homing. This method binds the socket to a single interface and effectively disables multi-homing. This method is only here for completeness' sake.

Bind the socket to a spcific port/address. A socket can only be bound once.

Throws:
java.net.SocketException

close

public void close()
           throws java.net.SocketException
Close the socket. Closes the socket. It is better to close the socket explicitly than rely or Java's GC. note: This method waits for any otustanding receive() calls to finish.

Throws:
java.net.SocketException

isClosed

public boolean isClosed()
Returns the closed state of the socket.

Since:
0.5.3

subscribeEvents

public void subscribeEvents(sctp_event_subscribe ses)
                     throws java.net.SocketException
Subscribe to specific SCTP notifications.

Throws:
java.net.SocketException

configureAutoClose

public void configureAutoClose(int seconds)
                        throws java.net.SocketException
Configure the auto-close feature. Configures the auto-close timer, or disables it.

Parameters:
seconds - Number of seconds without traffic before automatically closing associations. 0 means disable.
Throws:
java.net.SocketException

configureBlocking

public void configureBlocking(boolean block)
                       throws java.net.SocketException
Set the blocking mode. The blocking mode on SCTP sockets affects only two operations: connect() and send(). When configured in non-blocking connect() will return before the association is established and you should subscribe to the sctp_association_event (see subscribeEvents(dk.i1.sctp.sctp_event_subscribe)). When configured in non-blocking send() may throw the WouldBlockException exception if the send call would block (probably due to OS buffers being full).

Parameters:
block - If true then send() and connect() any block. If false then send() and connect() will not block
Throws:
java.net.SocketException

isBlocking

public boolean isBlocking()
                   throws java.net.SocketException
Tells whether send() and connect() may block.

Throws:
java.net.SocketException

setSctpNoDelay

public void setSctpNoDelay(boolean on)
                    throws java.net.SocketException
Enable/disable SCTP_NODELAY (disable/enable Nagle's algorithm).

Parameters:
on - true to enable TCP_NODELAY, false to disable.
Throws:
java.net.SocketException
Since:
0.5.4

getSctpNoDelay

public boolean getSctpNoDelay()
                       throws java.net.SocketException
Tests if SCTP_NODELAY is enabled.

Returns:
a boolean indicating whether or not SCTP_NODELAY is enabled.
Throws:
java.net.SocketException
Since:
0.5.4

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws java.net.SocketException
Get the SO_RCVBUF option for the socket.

Throws:
java.net.SocketException
Since:
0.5.7

getSendBufferSize

public int getSendBufferSize()
                      throws java.net.SocketException
Get the SO_SNDBUF option for the socket.

Throws:
java.net.SocketException
Since:
0.5.7

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws java.net.SocketException
Sets the SO_RCVBUF option for this socket.

Throws:
java.net.SocketException
Since:
0.5.7

setSendBufferSize

public void setSendBufferSize(int size)
                       throws java.net.SocketException
Sets the SO_SNDBUF option for this socket.

Throws:
java.net.SocketException
Since:
0.5.7

setPeerParameters

public void setPeerParameters(sctp_paddrparams spp)
                       throws java.net.SocketException
Set the parameters for a peer. Sets the parameters for a peer, heartbeat interval among others.

Throws:
java.net.SocketException

setInitMsg

public void setInitMsg(sctp_initmsg im)
                throws java.net.SocketException
Set default association parameters. Setting initialization parameters is effective only on an unconnected socket (for one-to-many style sockets only future associations are effected by the change). With one-to-one style sockets, this option is inherited by sockets derived from a listener socket.

Throws:
java.net.SocketException
Since:
0.5.6

listen

public void listen()
            throws java.net.SocketException
Enable inbound connections. Until listen() has been called inbound associations are not accepted.

Throws:
java.net.SocketException

connect

public void connect(java.net.InetSocketAddress addr)
             throws java.net.SocketException
Create an association to a peer. Creates an association to a peer. Explicit association creation is not needed, but probably a good idea.

Throws:
java.net.SocketException

connect

public void connect(java.net.InetAddress addr,
                    int port)
             throws java.net.SocketException
Create an association to a peer. Creates an association to a peer. Explicit association creation is not needed, but probably a good idea.

Throws:
java.net.SocketException

disconnect

public void disconnect(AssociationId assoc_id)
                throws java.net.SocketException
Shut down an association.

Throws:
java.net.SocketException

disconnect

public void disconnect(AssociationId assoc_id,
                       boolean gracefully)
                throws java.net.SocketException
Shut down an association.

Parameters:
assoc_id - The association to shut down
gracefully - Controls whether the association is shut down gracefully with SCTP_EOF, or with SCTP_ABORT.
Throws:
java.net.SocketException

getLocalInetAddresses

public java.util.Collection<java.net.InetAddress> getLocalInetAddresses()
                                                                 throws java.net.SocketException
Get local addressed uses by the socket. Retrieves the list of local addresses the socket can be contacted on. The list usually includes loopback-addresses, public ip-address and link-local addresses.

Throws:
java.net.SocketException

getLocalInetAddresses

public java.util.Collection<java.net.InetAddress> getLocalInetAddresses(AssociationId assoc_id)
                                                                 throws java.net.SocketException
Get local addresses used by the socket. Retrieves the list of local addresses the socket can be contacted on. The list usually includes loopback-addresses, public ip-address and link-local addresses.

Throws:
java.net.SocketException

getLocalInetPort

public int getLocalInetPort()
                     throws java.net.SocketException
Get local port. Retrieves the local port the socket is bound to. This is useful if you did not specify a specific port to bind to in the call to bind().

Throws:
java.net.SocketException

getPeerInetAddresses

public java.util.Collection<java.net.InetAddress> getPeerInetAddresses(AssociationId assoc_id)
Get addresses of a peer. Retrieves a list of known addresses of a peer, including non-reachable addresses.


getPeerInetPort

public int getPeerInetPort(AssociationId assoc_id)
                    throws java.net.SocketException
Throws:
java.net.SocketException

chunkAvailable

public boolean chunkAvailable()
                       throws java.net.SocketException
Probe if any unread chunks are pending

Returns:
true if any chunks are pending reading
Throws:
java.net.SocketException

receive

public SCTPChunk receive()
                  throws java.net.SocketException
Receive a data chunk or a notification. Implemented as receive(0)

Returns:
a SCTPChunk, or, in some cases, null
Throws:
java.net.SocketException

receiveNow

public SCTPChunk receiveNow()
                     throws java.net.SocketException
Receive a data chunk or a notification. If no events are available the call returns immediately with null.

Returns:
a SCTPChunk, or, in some cases, null
Throws:
java.net.SocketException

receive

public SCTPChunk receive(long timeout)
                  throws java.net.SocketException,
                         java.lang.IllegalArgumentException
Receive a data chunk or a notification.

Parameters:
timeout - Milliseconds to wait for an event. 0 means infinite. Must not be negative.
Returns:
a SCTPChunk, or, in some cases, null
Throws:
java.net.SocketException
java.lang.IllegalArgumentException

send

public void send(SCTPData sctpdata)
          throws java.net.SocketException,
                 WouldBlockException
Send a datagram to a peer. Sends the data chunk to a peer. The peer is specified in sctpdata.sndrcvinfo.sinfo_assoc_id.

Example:

        SCTPData data = new SCTPData(raw_byte_array);
        data.sndrcvinfo.sinfo_assoc_id = destination_association_id;
        sctp_socket.send(data);
        

Parameters:
sctpdata - the data chunk to send.
Throws:
java.net.SocketException - if a socket error occurs.
WouldBlockException - if the socket is non-blocking and outgoing OS buffers are full.

wakeup

public void wakeup()
            throws java.net.SocketException
Wake other threads from receive(). Wakes 1 thread that is currently blocking in a receive() call. This method is only meant for clean shutdown, and is not as nice and the equivalent method in java.nio.Selector. The woken thread will return null.

Throws:
java.net.SocketException