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 Summary
Modifier and Type Method Description default int
convertTimeout(Integer timeout)
Convert a timeout into a primitive type.InetAddress
getLocalIPAddress()
int
getLocalPort()
InetAddress
getRemoteIPAddress()
int
getRemotePort()
boolean
isClosed()
Determines if the medium is closed at this point in time.boolean
isConnected()
Determines if the medium is connected at this point in time.ByteBuffer
receive(Integer timeout)
Receive data from the connection.UDPPacket
receiveWithAddress(int timeout)
Receive data from the connection along with the address where the data was received from.void
send(ByteBuffer data)
Send data down this connection.void
sendTo(ByteBuffer data, InetAddress address, int port)
Send data down this connection.
-
Method Details
-
isConnected
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
Convert a timeout into a primitive type.- Parameters:
timeout
- The timeout in milliseconds, ornull
to wait "forever".- Returns:
- The primitive timeout.
-
receive
ByteBuffer receive(Integer timeout) throws SocketTimeoutException, IOException, InterruptedExceptionReceive data from the connection.- Parameters:
timeout
- The timeout in milliseconds, ornull
to wait forever- Returns:
- The data received, in a little-endian buffer
- Throws:
SocketTimeoutException
- If a timeout occurs before any data is receivedEOFException
- If the connection is closedIOException
- If an error occurs receiving the dataInterruptedException
- If communications are interrupted.
-
receiveWithAddress
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 receivedEOFException
- If the connection is closedIOException
- If an error occurs receiving the data
-
send
Send data down this connection.- Parameters:
data
- The data to be sent- Throws:
EOFException
- If the connection is closedIOException
- If there is an error sending the dataIllegalStateException
- If the data buffer doesn't hold a message; zero-length messages are not supported!
-
sendTo
Send data down this connection.- Parameters:
data
- The data to be sentaddress
- Where to send (must be non-null
)port
- What port to send to (must be non-zero)- Throws:
EOFException
- If the connection is closedIOException
- If there is an error sending the dataIllegalStateException
- If the data packet doesn't hold a real message; zero-length messages are not supported!
-