Package org.km3net.clb.remote.stack
Class SRPSocket
- java.lang.Object
-
- org.km3net.clb.remote.stack.SRPSocket
-
public class SRPSocket extends java.lang.Object
Implements the Simple Retransmission Protocol (SRP). SRP is a layer on top of UDP for reliable packet transport. Unlike TCP however it is connectionless and stateless and not based on streams. SRP socket may also be set into broadcasting mode when provided with a broadcast address. In these cases messages will just be send multiple times to increase reliability. For performance SRP uses non-blocking IO.
-
-
Field Summary
Fields Modifier and Type Field Description static SRPPacketDecorator
DECO
-
Constructor Summary
Constructors Constructor Description SRPSocket(java.net.Inet4Address remoteAddr, int remotePort)
Create an SRP socket to the given remote address.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the socketprotected void
finalize()
SRPSocketCallback
getCallback()
Gets the SRP callback.java.net.Inet4Address
getLocalAddress()
java.net.Inet4Address
getRemoteAddress()
boolean
isBroadcast()
Returns whether or not this is a broadcasting socket.java.net.SocketAddress
localAddress()
byte[]
receive()
Receives data.boolean
receivePending()
Returns whether there is anything to receive.java.net.SocketAddress
remoteAddress()
void
send(byte[] data)
Send data onto the network.void
setCallback(SRPSocketCallback callback)
Sets the SRP Callback.int
transactionCount()
Returns the number of active transactions.
-
-
-
Field Detail
-
DECO
public static SRPPacketDecorator DECO
-
-
Constructor Detail
-
SRPSocket
public SRPSocket(java.net.Inet4Address remoteAddr, int remotePort) throws java.io.IOException
Create an SRP socket to the given remote address.- Parameters:
remoteAddr
- The remote address to send to, or broadcast address.remotePort
- The remote port to send to.- Throws:
java.io.IOException
- When the socket could not be created.
-
-
Method Detail
-
setCallback
public void setCallback(SRPSocketCallback callback)
Sets the SRP Callback.- Parameters:
callback
- The callback.
-
getCallback
public SRPSocketCallback getCallback()
Gets the SRP callback.- Returns:
- The callback object.
-
getRemoteAddress
public java.net.Inet4Address getRemoteAddress()
-
getLocalAddress
public java.net.Inet4Address getLocalAddress()
-
isBroadcast
public boolean isBroadcast()
Returns whether or not this is a broadcasting socket.- Returns:
true
if it is in broadcast mode,false
if it is in unicast mode.
-
send
public void send(byte[] data) throws java.io.IOException
Send data onto the network.- Parameters:
data
- The data to send.- Throws:
java.io.IOException
- If the socket was closed unexpectedly.
-
receivePending
public boolean receivePending()
Returns whether there is anything to receive.- Returns:
true
if it is data to receive,false
if there is not.
-
receive
public byte[] receive()
Receives data. Does not block.- Returns:
null
if there is nothing to receive, otherwise an array of data.
-
close
public void close() throws java.lang.InterruptedException
Closes the socket- Throws:
java.lang.InterruptedException
- When the closing process was interrupted.
-
remoteAddress
public java.net.SocketAddress remoteAddress()
-
localAddress
public java.net.SocketAddress localAddress()
-
transactionCount
public int transactionCount()
Returns the number of active transactions.
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
-