Skip to content
This repository was archived by the owner on Aug 24, 2021. It is now read-only.
This repository was archived by the owner on Aug 24, 2021. It is now read-only.

onBluetoothDeviceDisconnected Callback don't work #3

@paloky

Description

@paloky

Hi.
I try the SPPServerActivity for a SPP Server Mode.
This works fine... The PC open the SPP port, and I can send and receive messages in App.
The problem is when el Client close the connection.
A Exception occurs on SPPServerController, and I don't receive "onBluetoothDeviceDisconnected" Callback, to bind a new connection.

 java.io.IOException: bt socket closed, read return: -1
        at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:558)
        at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:88)
        at java.io.InputStream.read(InputStream.java:101)
        at me.kudryavka.bluecon.SPPServer.SPPServerController$CommunicationThread$ReadThread.run(SPPServerController.java:423)

The Exception is generate here. In SPPServerController.java, when try to read a closed socket.

  @Override
            public void run() {
                byte[] data = new byte[buffSize];
                int len;

                while (true) {
                    try {
                        len = inputStream.read(data);
                        byte[] read = new byte[len];
                        System.arraycopy(data, 0, read, 0, len);
                        for (SPPListener sppListener : sppListeners) {
                            sppListener.onPacketReceived(socket.getRemoteDevice().getAddress(), read);
                        }
                    } catch (IOException e) {
                        Log.e(TAG, "CONNECTION CLOSED BY PEER", e);
                        disconnected(socket, this);
                        break;
                    }
                }
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions