Package org.km3net.clb.remote.stack
Class SRPSocket
- java.lang.Object
-
- org.km3net.clb.remote.stack.SRPSocket
-
public class SRPSocket extends java.lang.ObjectImplements 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 SRPPacketDecoratorDECO
-
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 voidclose()Closes the socketprotected voidfinalize()SRPSocketCallbackgetCallback()Gets the SRP callback.java.net.Inet4AddressgetLocalAddress()java.net.Inet4AddressgetRemoteAddress()booleanisBroadcast()Returns whether or not this is a broadcasting socket.java.net.SocketAddresslocalAddress()byte[]receive()Receives data.booleanreceivePending()Returns whether there is anything to receive.java.net.SocketAddressremoteAddress()voidsend(byte[] data)Send data onto the network.voidsetCallback(SRPSocketCallback callback)Sets the SRP Callback.inttransactionCount()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.IOExceptionCreate 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:
trueif it is in broadcast mode,falseif it is in unicast mode.
-
send
public void send(byte[] data) throws java.io.IOExceptionSend 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:
trueif it is data to receive,falseif there is not.
-
receive
public byte[] receive()
Receives data. Does not block.- Returns:
nullif there is nothing to receive, otherwise an array of data.
-
close
public void close() throws java.lang.InterruptedExceptionCloses 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:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-