Class 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
    • Constructor Detail

      • IPConnectionBase

        public IPConnectionBase()
    • 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.
        Throws:
        NetworkException
        AlreadyConnectedException
      • close

        public void close()
                   throws java.io.IOException
        Implement Closable interface to allow something like try (IPConnection ipcon = new IPConnection()) { }
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • 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.
      • 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)