Package com.tinkerforge
Class IPConnectionBase
- java.lang.Object
-
- com.tinkerforge.IPConnectionBase
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
- Direct Known Subclasses:
IPConnection
public abstract class IPConnectionBase extends java.lang.Object implements java.io.Closeable
-
-
Field Summary
Fields Modifier and Type Field Description static byte
CALLBACK_CONNECTED
static byte
CALLBACK_DISCONNECTED
static byte
CALLBACK_ENUMERATE
static short
CONNECT_REASON_AUTO_RECONNECT
static short
CONNECT_REASON_REQUEST
static short
CONNECTION_STATE_CONNECTED
static short
CONNECTION_STATE_DISCONNECTED
static short
CONNECTION_STATE_PENDING
static short
DISCONNECT_REASON_ERROR
static short
DISCONNECT_REASON_REQUEST
static short
DISCONNECT_REASON_SHUTDOWN
static short
ENUMERATION_TYPE_AVAILABLE
static short
ENUMERATION_TYPE_CONNECTED
static short
ENUMERATION_TYPE_DISCONNECTED
static byte
FUNCTION_ENUMERATE
-
Constructor Summary
Constructors Constructor Description IPConnectionBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
authenticate(java.lang.String secret)
Performs an authentication handshake with the connected Brick Daemon or WIFI/Ethernet Extension.protected abstract void
callConnectedListeners(short connectReason)
protected abstract void
callDeviceListener(Device device, byte functionID, byte[] packet)
protected abstract void
callDisconnectedListeners(short disconnectReason)
protected abstract void
callEnumerateListeners(java.lang.String uid, java.lang.String connectedUid, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType)
void
close()
Implement Closable interface to allow something like try (IPConnection ipcon = new IPConnection()) { }void
connect(java.lang.String host, int port)
Creates a TCP/IP connection to the given \c host and \c port.void
disconnect()
Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet Extension.void
enumerate()
Broadcasts an enumerate request.boolean
getAutoReconnect()
Returns *true* if auto-reconnect is enabled, *false* otherwise.short
getConnectionState()
Can return the following states: - CONNECTION_STATE_DISCONNECTED: No connection is established.int
getTimeout()
Returns the timeout as set by setTimeout.protected abstract boolean
hasEnumerateListeners()
void
setAutoReconnect(boolean autoReconnect)
Enables or disables auto-reconnect.void
setTimeout(int timeout)
Sets the timeout in milliseconds for getters and for setters for which the response expected flag is activated.
-
-
-
Field Detail
-
FUNCTION_ENUMERATE
public static final byte FUNCTION_ENUMERATE
- See Also:
- Constant Field Values
-
CALLBACK_ENUMERATE
public static final byte CALLBACK_ENUMERATE
- See Also:
- Constant Field Values
-
CALLBACK_CONNECTED
public static final byte CALLBACK_CONNECTED
- See Also:
- Constant Field Values
-
CALLBACK_DISCONNECTED
public static final byte CALLBACK_DISCONNECTED
- See Also:
- Constant Field Values
-
ENUMERATION_TYPE_AVAILABLE
public static final short ENUMERATION_TYPE_AVAILABLE
- See Also:
- Constant Field Values
-
ENUMERATION_TYPE_CONNECTED
public static final short ENUMERATION_TYPE_CONNECTED
- See Also:
- Constant Field Values
-
ENUMERATION_TYPE_DISCONNECTED
public static final short ENUMERATION_TYPE_DISCONNECTED
- See Also:
- Constant Field Values
-
CONNECT_REASON_REQUEST
public static final short CONNECT_REASON_REQUEST
- See Also:
- Constant Field Values
-
CONNECT_REASON_AUTO_RECONNECT
public static final short CONNECT_REASON_AUTO_RECONNECT
- See Also:
- Constant Field Values
-
DISCONNECT_REASON_REQUEST
public static final short DISCONNECT_REASON_REQUEST
- See Also:
- Constant Field Values
-
DISCONNECT_REASON_ERROR
public static final short DISCONNECT_REASON_ERROR
- See Also:
- Constant Field Values
-
DISCONNECT_REASON_SHUTDOWN
public static final short DISCONNECT_REASON_SHUTDOWN
- See Also:
- Constant Field Values
-
CONNECTION_STATE_DISCONNECTED
public static final short CONNECTION_STATE_DISCONNECTED
- See Also:
- Constant Field Values
-
CONNECTION_STATE_CONNECTED
public static final short CONNECTION_STATE_CONNECTED
- See Also:
- Constant Field Values
-
CONNECTION_STATE_PENDING
public static final short CONNECTION_STATE_PENDING
- See Also:
- Constant Field Values
-
-
Method Detail
-
connect
public void connect(java.lang.String host, int port) throws NetworkException, AlreadyConnectedException
Creates a TCP/IP connection to the given \c host and \c port. The host and port can point to a Brick Daemon or to a WIFI/Ethernet Extension. Devices can only be controlled when the connection was established successfully. Blocks until the connection is established and throws an exception if there is no Brick Daemon or WIFI/Ethernet Extension listening at the given host and port.
-
close
public void close() throws java.io.IOException
Implement Closable interface to allow something like try (IPConnection ipcon = new IPConnection()) { }- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
disconnect
public void disconnect() throws NotConnectedException
Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet Extension.- Throws:
NotConnectedException
-
authenticate
public void authenticate(java.lang.String secret) throws TinkerforgeException
Performs an authentication handshake with the connected Brick Daemon or WIFI/Ethernet Extension. If the handshake succeeds the connection switches from non-authenticated to authenticated state and communication can continue as normal. If the handshake fails then the connection gets closed. Authentication can fail if the wrong secret was used or if authentication is not enabled at all on the Brick Daemon or the WIFI/Ethernet Extension. For more information about authentication see https://www.tinkerforge.com/en/doc/Tutorials/Tutorial_Authentication/Tutorial.html- Throws:
TinkerforgeException
-
getConnectionState
public short getConnectionState()
Can return the following states: - CONNECTION_STATE_DISCONNECTED: No connection is established. - CONNECTION_STATE_CONNECTED: A connection to the Brick Daemon or the WIFI/Ethernet Extension is established. - CONNECTION_STATE_PENDING: IP Connection is currently trying to connect.
-
setAutoReconnect
public void setAutoReconnect(boolean autoReconnect)
Enables or disables auto-reconnect. If auto-reconnect is enabled, the IP Connection will try to reconnect to the previously given host and port, if the connection is lost. Default value is *true*.
-
getAutoReconnect
public boolean getAutoReconnect()
Returns *true* if auto-reconnect is enabled, *false* otherwise.
-
setTimeout
public void setTimeout(int timeout)
Sets the timeout in milliseconds for getters and for setters for which the response expected flag is activated. Default timeout is 2500.
-
getTimeout
public int getTimeout()
Returns the timeout as set by setTimeout.
-
enumerate
public void enumerate() throws NotConnectedException
Broadcasts an enumerate request. All devices will respond with an enumerate callback.- Throws:
NotConnectedException
-
callEnumerateListeners
protected abstract void callEnumerateListeners(java.lang.String uid, java.lang.String connectedUid, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType)
-
hasEnumerateListeners
protected abstract boolean hasEnumerateListeners()
-
callConnectedListeners
protected abstract void callConnectedListeners(short connectReason)
-
callDisconnectedListeners
protected abstract void callDisconnectedListeners(short disconnectReason)
-
callDeviceListener
protected abstract void callDeviceListener(Device device, byte functionID, byte[] packet)
-
-