Class SerialPortServer

  • All Implemented Interfaces:
    ej.bluetooth.listeners.LocalServiceListener

    public abstract class SerialPortServer
    extends ej.bluetooth.listeners.impl.DefaultLocalServiceListener
    The SerialPortServer class represents a serial port server.
    • Constructor Summary

      Constructors 
      Constructor Description
      SerialPortServer​(ej.bluetooth.BluetoothService service)
      Creates a serial port server, using the serial port service provided by this device.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void onDataReceived​(ej.bluetooth.BluetoothConnection connection, byte[] data)
      Called when data has been received from a client.
      protected abstract void onDataSent​(ej.bluetooth.BluetoothConnection connection, boolean success)
      Called when data has been sent to a client.
      void onNotificationSent​(ej.bluetooth.BluetoothConnection connection, ej.bluetooth.BluetoothCharacteristic characteristic, boolean success)  
      void onReadRequest​(ej.bluetooth.BluetoothConnection connection, ej.bluetooth.BluetoothAttribute attribute)  
      void onWriteRequest​(ej.bluetooth.BluetoothConnection connection, ej.bluetooth.BluetoothAttribute attribute, byte[] value)  
      void sendData​(ej.bluetooth.BluetoothConnection connection, byte[] data)
      Sends the given data to the given client.
      void start()
      Starts this serial port server.
      void stop()
      Stops this serial port server.
      • Methods inherited from class ej.bluetooth.listeners.impl.DefaultLocalServiceListener

        onExecuteWriteRequest, onPrepareWriteRequest, onReadBlobRequest
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SerialPortServer

        public SerialPortServer​(ej.bluetooth.BluetoothService service)
        Creates a serial port server, using the serial port service provided by this device.
        Parameters:
        service - the serial port service provided by this device.
        Throws:
        java.lang.IllegalArgumentException - if one of the mandatory attributes of the service is missing.
    • Method Detail

      • start

        public void start()
        Starts this serial port server.
      • stop

        public void stop()
        Stops this serial port server.
      • sendData

        public void sendData​(ej.bluetooth.BluetoothConnection connection,
                             byte[] data)
        Sends the given data to the given client. The onDataSent(BluetoothConnection, boolean) methods is called once the data has been sent to the client.
        Parameters:
        connection - the connection to the device to which the data should be sent.
        data - the data to send.
      • onReadRequest

        public void onReadRequest​(ej.bluetooth.BluetoothConnection connection,
                                  ej.bluetooth.BluetoothAttribute attribute)
        Specified by:
        onReadRequest in interface ej.bluetooth.listeners.LocalServiceListener
        Overrides:
        onReadRequest in class ej.bluetooth.listeners.impl.DefaultLocalServiceListener
      • onWriteRequest

        public void onWriteRequest​(ej.bluetooth.BluetoothConnection connection,
                                   ej.bluetooth.BluetoothAttribute attribute,
                                   byte[] value)
        Specified by:
        onWriteRequest in interface ej.bluetooth.listeners.LocalServiceListener
        Overrides:
        onWriteRequest in class ej.bluetooth.listeners.impl.DefaultLocalServiceListener
      • onNotificationSent

        public void onNotificationSent​(ej.bluetooth.BluetoothConnection connection,
                                       ej.bluetooth.BluetoothCharacteristic characteristic,
                                       boolean success)
        Specified by:
        onNotificationSent in interface ej.bluetooth.listeners.LocalServiceListener
        Overrides:
        onNotificationSent in class ej.bluetooth.listeners.impl.DefaultLocalServiceListener
      • onDataReceived

        protected abstract void onDataReceived​(ej.bluetooth.BluetoothConnection connection,
                                               byte[] data)
        Called when data has been received from a client.
        Parameters:
        connection - the connection to the device from which the data has been received.
        data - the data received from the client.
      • onDataSent

        protected abstract void onDataSent​(ej.bluetooth.BluetoothConnection connection,
                                           boolean success)
        Called when data has been sent to a client.
        Parameters:
        connection - the connection to the device to which the data has been sent.
        success - true if the the data was sent successfully, false otherwise.