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 Details

  • Method Details

    • addConnection

      protected abstract void addConnection​(Connection connection)
      Add a connection to the collection of general connections managed by this class.
      Parameters:
      connection - the connection to add
    • close

      public void close() throws IOException
      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 interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - Not thrown. Subclasses may (do!) throw it.
    • registerEIEIOListener

      public final EIEIOConnection registerEIEIOListener​(EIEIOMessageHandler callback, int localPort, InetAddress localHost) throws IOException
      Register a callback for EIEIO traffic to be received.
      Parameters:
      callback - Function to be called when a packet is received. Must not be null.
      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 used
      localHost - 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 IOException
      Create an EIEIO connection only available for listening (or directed sending towards a SpiNNaker board).
      Parameters:
      localHost - The local IP address to bind to. If null, 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 IOException
      Register a callback for EIEIO traffic to be received.
      Parameters:
      callback - Function to be called when a packet is received. Must not be null.
      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 IOException
      Register a callback for EIEIO traffic to be received.
      Parameters:
      callback - Function to be called when a packet is received. Must not be null.
      Returns:
      The connection to be used
      Throws:
      IllegalArgumentException - If basic sanity checks fail.
      IOException - If the networking fails.