Class UDPTransceiver
java.lang.Object
uk.ac.manchester.spinnaker.transceiver.UDPTransceiver
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
Transceiver
public abstract class UDPTransceiver extends Object implements Closeable
A simple transceiver for UDP connections. In particular, handles managing the
connection listeners for EIEIO connections and ensuring that connections are
not double-registered.
- Author:
- Donal Fellows
-
Constructor Summary
Constructors Constructor Description UDPTransceiver()
-
Method Summary
Modifier and Type Method Description protected abstract void
addConnection(Connection connection)
Add a connection to the collection of general connections managed by this class.void
close()
Shut down any listeners registered for the EIEIO connections.protected EIEIOConnection
newEieioConnection(InetAddress localHost, Integer localPort)
Create an EIEIO connection only available for listening (or directed sending towards a SpiNNaker board).EIEIOConnection
registerEIEIOListener(EIEIOMessageHandler callback)
Register a callback for EIEIO traffic to be received.EIEIOConnection
registerEIEIOListener(EIEIOMessageHandler callback, int localPort)
Register a callback for EIEIO traffic to be received.EIEIOConnection
registerEIEIOListener(EIEIOMessageHandler callback, int localPort, InetAddress localHost)
Register a callback for EIEIO traffic to be received.
-
Constructor Details
-
UDPTransceiver
public UDPTransceiver()
-
-
Method Details
-
addConnection
Add a connection to the collection of general connections managed by this class.- Parameters:
connection
- the connection to add
-
close
Shut down any listeners registered for the EIEIO connections. The connections are not closed; caller (or subclass) is responsible for that.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- Not thrown. Subclasses may (do!) throw it.
-
registerEIEIOListener
public final EIEIOConnection registerEIEIOListener(EIEIOMessageHandler callback, int localPort, InetAddress localHost) throws IOExceptionRegister a callback for EIEIO traffic to be received.- Parameters:
callback
- Function to be called when a packet is received. Must not benull
.localPort
- The optional port number to listen on; if not specified, an existing connection will be used if possible, otherwise a random free port number will be usedlocalHost
- The optional hostname or IP address to listen on; if not specified, all interfaces will be used for listening- Returns:
- The connection to be used
- Throws:
IllegalArgumentException
- If basic sanity checks fail.IOException
- If the networking fails.
-
newEieioConnection
protected EIEIOConnection newEieioConnection(InetAddress localHost, Integer localPort) throws IOExceptionCreate an EIEIO connection only available for listening (or directed sending towards a SpiNNaker board).- Parameters:
localHost
- The local IP address to bind to. Ifnull
, it defaults to binding to all interfaces or a system-specified interface.localPort
- The local port to bind to,null
or between 1025 and 65535.- Returns:
- The listen-only EIEIO connection.
- Throws:
IOException
- If there is an error setting up the communication channel
-
registerEIEIOListener
public final EIEIOConnection registerEIEIOListener(EIEIOMessageHandler callback, int localPort) throws IOExceptionRegister a callback for EIEIO traffic to be received.- Parameters:
callback
- Function to be called when a packet is received. Must not benull
.localPort
- The local UDP port to bind.- Returns:
- The connection to be used
- Throws:
IllegalArgumentException
- If basic sanity checks fail.IOException
- If the networking fails.
-
registerEIEIOListener
public final EIEIOConnection registerEIEIOListener(EIEIOMessageHandler callback) throws IOExceptionRegister a callback for EIEIO traffic to be received.- Parameters:
callback
- Function to be called when a packet is received. Must not benull
.- Returns:
- The connection to be used
- Throws:
IllegalArgumentException
- If basic sanity checks fail.IOException
- If the networking fails.
-