Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read failed, socket might closed or timeout, read ret: -1 #38

Open
OmarBeshary opened this issue Apr 15, 2018 · 3 comments
Open

read failed, socket might closed or timeout, read ret: -1 #38

OmarBeshary opened this issue Apr 15, 2018 · 3 comments

Comments

@OmarBeshary
Copy link

OmarBeshary commented Apr 15, 2018

Hi when i try to make a connection with a device it gives me this error

read failed, socket might closed or timeout, read ret: -1

After making a connection with the device , the phone send a connection request with a pair number and the other phone accepts it , but it still gives me the error.
this is my code
rxBluetooth.observeDevices() .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer<BluetoothDevice>() { @Override public void accept(BluetoothDevice bluetoothDevice) throws Exception { if(bluetoothDevice.getName() != null && bluetoothDevice.getName().equals("Test")) { Log.e("RxBt",bluetoothDevice.getName()); rxBluetooth.cancelDiscovery(); connectToDevice(bluetoothDevice); } if(bluetoothDevice.getAddress() != null) Log.e("RxBt",bluetoothDevice.getAddress()); //addDevice(bluetoothDevice); } });

Connecting to device method

private void connectToDevice(BluetoothDevice bluetoothDevice) { Log.e("connectToDevice()","connectToDevice invoked."); UUID uuid = UUID.fromString("f77d314e-9730-4a0b-a3a8-0d283eff53ea"); rxBluetooth.observeConnectDevice(bluetoothDevice, uuid) .observeOn(AndroidSchedulers.mainThread()) .subscribeOn(Schedulers.io()) .subscribe(new Consumer<BluetoothSocket>() { @Override public void accept(BluetoothSocket socket) throws Exception { // Connected to the device, do anything with the socket Log.e("connectToDevice()","Start of Connection."); } }, new Consumer<Throwable>() { @Override public void accept(Throwable throwable) throws Exception { Log.e("connectToDevice()",throwable.getMessage()); } }); }

@RanyAlbegWein
Copy link

Did you manage to solve this issue?
I'm stuck on the same thing.

Discovery works fine, but this library is useless when you can't actually connect.

@OmarBeshary
Copy link
Author

I didn't until now.

@RanyAlbegWein
Copy link

Seems like you need to observeBluetoothSocket to open a BluetoothServerSocket and listen for a connection request :

mRxBluetooth.observeBluetoothSocket("MyConnection", UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
                .subscribeOn(mSchedulerProvider.io())
                .observeOn(mSchedulerProvider.ui())
                .subscribe(new Consumer<BluetoothSocket>() {
                    @Override
                    public void accept(BluetoothSocket bluetoothSocket) throws Exception {
                        // ...
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                       // ...
                    }
                })`

then mRxBluetooth.observeConnectDevice(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants