Interface Connection

All Superinterfaces:
AutoCloseable, Closeable
All Known Subinterfaces:
SCPSenderReceiver
All Known Implementing Classes:
BMPConnection, BootConnection, DelegatingSCPConnection, EIEIOConnection, IPAddressConnection, NotificationConnection, ProxyUDPConnection, SCPConnection, SDPConnection, UDPConnection

public interface Connection
extends Closeable
An abstract connection to the SpiNNaker board over some medium. This resource class holds a network socket (or a proxy for one) and can answer basic questions about it.
  • Method Details

    • isConnected

      boolean isConnected() throws IOException
      Determines if the medium is connected at this point in time. Connected media are not closed. Disconnected media might not be open.
      Returns:
      true if the medium is connected, false otherwise
      Throws:
      IOException - If there is an error when determining the connectivity of the medium.
    • isClosed

      boolean isClosed()
      Determines if the medium is closed at this point in time. Closed media are not connected. Open media might not be connected.
      Returns:
      true if the medium is closed, false otherwise
    • getLocalIPAddress

      InetAddress getLocalIPAddress()
      Returns:
      the local (host) IP address of the socket. Expected to be an IPv4 address when talking to SpiNNaker.
    • getLocalPort

      int getLocalPort()
      Returns:
      the local (host) port of the socket.
    • getRemoteIPAddress

      InetAddress getRemoteIPAddress()
      Returns:
      the remote (board) IP address of the socket. Expected to be an IPv4 address when talking to SpiNNaker.
    • getRemotePort

      int getRemotePort()
      Returns:
      the remote (board) port of the socket.
    • convertTimeout

      default int convertTimeout​(Integer timeout)
      Convert a timeout into a primitive type.
      Parameters:
      timeout - The timeout in milliseconds, or null to wait "forever".
      Returns:
      The primitive timeout.
    • receive

      Receive data from the connection.
      Parameters:
      timeout - The timeout in milliseconds, or null to wait forever
      Returns:
      The data received, in a little-endian buffer
      Throws:
      SocketTimeoutException - If a timeout occurs before any data is received
      EOFException - If the connection is closed
      IOException - If an error occurs receiving the data
      InterruptedException - If communications are interrupted.
    • receiveWithAddress

      UDPPacket receiveWithAddress​(int timeout) throws SocketTimeoutException, IOException
      Receive data from the connection along with the address where the data was received from.
      Parameters:
      timeout - The timeout in milliseconds
      Returns:
      The datagram packet received; caller is responsible for only accessing the valid part of the buffer.
      Throws:
      SocketTimeoutException - If a timeout occurs before any data is received
      EOFException - If the connection is closed
      IOException - If an error occurs receiving the data
    • send

      void send​(ByteBuffer data) throws IOException
      Send data down this connection.
      Parameters:
      data - The data to be sent
      Throws:
      EOFException - If the connection is closed
      IOException - If there is an error sending the data
      IllegalStateException - If the data buffer doesn't hold a message; zero-length messages are not supported!
    • sendTo

      void sendTo​(ByteBuffer data, InetAddress address, int port) throws IOException
      Send data down this connection.
      Parameters:
      data - The data to be sent
      address - Where to send (must be non-null)
      port - What port to send to (must be non-zero)
      Throws:
      EOFException - If the connection is closed
      IOException - If there is an error sending the data
      IllegalStateException - If the data packet doesn't hold a real message; zero-length messages are not supported!