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

Client Instance crashes app #2

Open
tsdogs opened this issue Dec 9, 2017 · 4 comments
Open

Client Instance crashes app #2

tsdogs opened this issue Dec 9, 2017 · 4 comments

Comments

@tsdogs
Copy link

tsdogs commented Dec 9, 2017

Server instance works great, but If I use a client instance the app tries to connect a couple of times to the client, but then it crashes the app. (even if the device is not reachable)

This are the errors, and I also have no idea on why it's saying it's connected when this cannot be (device was off, but it's basically doing the same when device is on):

12-09 16:01:57.272 9504-9561/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:01:57.276 9504-9561/com.metalit.ondaweb D/SPPClientController: CONNECTED : 00:1D:A5:68:98:8C
12-09 16:01:57.277 9504-9678/com.metalit.ondaweb W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
12-09 16:01:57.284 9504-9679/com.metalit.ondaweb E/SPPClientController: FAILED TO READ PACKET
                                                                        java.io.IOException: socket closed
                                                                            at android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:104)
                                                                            at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:571)
                                                                            at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
                                                                            at java.io.InputStream.read(InputStream.java:101)
                                                                            at me.kudryavka.bluecon.SPPClient.SPPClientController$CommunicationThread.run(SPPClientController.java:336)
12-09 16:01:57.284 9504-9679/com.metalit.ondaweb D/SPPClientController: RECONNECT TO : 00:1D:A5:68:98:8C
12-09 16:01:57.284 9504-9679/com.metalit.ondaweb D/OndaWEB: BT device disconnected: 00:1D:A5:68:98:8C
12-09 16:01:57.284 9504-9679/com.metalit.ondaweb D/SPPClientController: CONNECT TO : 00:1D:A5:68:98:8C
12-09 16:01:57.292 9504-9561/com.metalit.ondaweb D/OndaWEB: BT Connected: 00:1D:A5:68:98:8C : OBDII
12-09 16:01:57.295 9504-9679/com.metalit.ondaweb D/OndaWEB: BT device connecting: 00:1D:A5:68:98:8C
12-09 16:01:57.296 9504-9680/com.metalit.ondaweb W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
12-09 16:02:02.539 9504-9678/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.539 9504-9680/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.541 9504-9678/com.metalit.ondaweb D/SPPClientController: CONNECTED : 00:1D:A5:68:98:8C
12-09 16:02:02.546 9504-9678/com.metalit.ondaweb D/OndaWEB: BT Connected: 00:1D:A5:68:98:8C : OBDII
12-09 16:02:02.546 9504-9759/com.metalit.ondaweb W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
12-09 16:02:02.548 9504-9760/com.metalit.ondaweb E/SPPClientController: FAILED TO READ PACKET
                                                                        java.io.IOException: socket closed
                                                                            at android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:104)
                                                                            at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:571)
                                                                            at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
                                                                            at java.io.InputStream.read(InputStream.java:101)
                                                                            at me.kudryavka.bluecon.SPPClient.SPPClientController$CommunicationThread.run(SPPClientController.java:336)
12-09 16:02:02.548 9504-9760/com.metalit.ondaweb D/SPPClientController: RECONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.549 9504-9760/com.metalit.ondaweb D/OndaWEB: BT device disconnected: 00:1D:A5:68:98:8C
12-09 16:02:02.549 9504-9760/com.metalit.ondaweb D/SPPClientController: CONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.549 9504-9680/com.metalit.ondaweb D/SPPClientController: CONNECTED : 00:1D:A5:68:98:8C
12-09 16:02:02.552 9504-9759/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.552 9504-9761/com.metalit.ondaweb W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
12-09 16:02:02.554 9504-9762/com.metalit.ondaweb E/SPPClientController: FAILED TO READ PACKET
                                                                        java.io.IOException: socket closed
                                                                            at android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:104)
                                                                            at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:571)
                                                                            at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
                                                                            at java.io.InputStream.read(InputStream.java:101)
                                                                            at me.kudryavka.bluecon.SPPClient.SPPClientController$CommunicationThread.run(SPPClientController.java:336)
12-09 16:02:02.554 9504-9762/com.metalit.ondaweb D/SPPClientController: RECONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.555 9504-9762/com.metalit.ondaweb D/OndaWEB: BT device disconnected: 00:1D:A5:68:98:8C
12-09 16:02:02.555 9504-9762/com.metalit.ondaweb D/SPPClientController: CONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.558 9504-9761/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.561 9504-9680/com.metalit.ondaweb D/OndaWEB: BT Connected: 00:1D:A5:68:98:8C : OBDII
12-09 16:02:02.564 9504-9759/com.metalit.ondaweb D/SPPClientController: CONNECTED : 00:1D:A5:68:98:8C
12-09 16:02:02.569 9504-9759/com.metalit.ondaweb D/OndaWEB: BT Connected: 00:1D:A5:68:98:8C : OBDII
12-09 16:02:02.569 9504-9763/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.572 9504-9762/com.metalit.ondaweb D/OndaWEB: BT device connecting: 00:1D:A5:68:98:8C
12-09 16:02:02.573 9504-9760/com.metalit.ondaweb D/OndaWEB: BT device connecting: 00:1D:A5:68:98:8C
12-09 16:02:02.574 9504-9764/com.metalit.ondaweb E/SPPClientController: FAILED TO READ PACKET
                                                                        java.io.IOException: socket closed
                                                                            at android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:104)
                                                                            at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:571)
                                                                            at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
                                                                            at java.io.InputStream.read(InputStream.java:101)
                                                                            at me.kudryavka.bluecon.SPPClient.SPPClientController$CommunicationThread.run(SPPClientController.java:336)
12-09 16:02:02.575 9504-9764/com.metalit.ondaweb D/SPPClientController: RECONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.575 9504-9764/com.metalit.ondaweb D/OndaWEB: BT device disconnected: 00:1D:A5:68:98:8C
12-09 16:02:02.575 9504-9764/com.metalit.ondaweb D/SPPClientController: CONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.577 9504-9765/com.metalit.ondaweb W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
12-09 16:02:02.580 9504-9766/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.581 9504-9767/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.581 9504-9763/com.metalit.ondaweb D/SPPClientController: CONNECTED : 00:1D:A5:68:98:8C
12-09 16:02:02.584 9504-9765/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.589 9504-9763/com.metalit.ondaweb D/OndaWEB: BT Connected: 00:1D:A5:68:98:8C : OBDII
12-09 16:02:02.589 9504-9761/com.metalit.ondaweb D/SPPClientController: CONNECTED : 00:1D:A5:68:98:8C
12-09 16:02:02.589 9504-9768/com.metalit.ondaweb W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
12-09 16:02:02.594 9504-9761/com.metalit.ondaweb D/OndaWEB: BT Connected: 00:1D:A5:68:98:8C : OBDII
12-09 16:02:02.598 9504-9767/com.metalit.ondaweb D/SPPClientController: CONNECTED : 00:1D:A5:68:98:8C
12-09 16:02:02.598 9504-9768/com.metalit.ondaweb E/SPPClientController: Failed to connect to SOCKET. retrying...
12-09 16:02:02.600 9504-9770/com.metalit.ondaweb E/SPPClientController: FAILED TO READ PACKET
                                                                        java.io.IOException: socket closed
                                                                            at android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:104)
                                                                            at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:571)
                                                                            at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
                                                                            at java.io.InputStream.read(InputStream.java:101)
                                                                            at me.kudryavka.bluecon.SPPClient.SPPClientController$CommunicationThread.run(SPPClientController.java:336)
12-09 16:02:02.600 9504-9769/com.metalit.ondaweb E/AndroidRuntime: FATAL EXCEPTION: Thread-20
                                                                   Process: com.metalit.ondaweb, PID: 9504
                                                                   java.lang.NullPointerException: Attempt to invoke virtual method 'int java.io.InputStream.read(byte[], int, int)' on a null object reference
                                                                       at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:571)
                                                                       at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
                                                                       at java.io.InputStream.read(InputStream.java:101)
                                                                       at me.kudryavka.bluecon.SPPClient.SPPClientController$CommunicationThread.run(SPPClientController.java:336)
12-09 16:02:02.600 9504-9770/com.metalit.ondaweb D/SPPClientController: RECONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.600 9504-9770/com.metalit.ondaweb D/OndaWEB: BT device disconnected: 00:1D:A5:68:98:8C
12-09 16:02:02.600 9504-9770/com.metalit.ondaweb D/SPPClientController: CONNECT TO : 00:1D:A5:68:98:8C
12-09 16:02:02.603 9504-9767/com.metalit.ondaweb D/OndaWEB: BT Connected: 00:1D:A5:68:98:8C : OBDII
12-09 16:02:02.605 9504-9772/com.metalit.ondaweb I/Process: Sending signal. PID: 9504 SIG: 9
@tsdogs
Copy link
Author

tsdogs commented Dec 11, 2017

this solved the issue:

index 9a7eac8..bc2c6fa 100644
--- a/bluecon/src/main/java/me/kudryavka/bluecon/SPPClient/SPPClientController.java
+++ b/bluecon/src/main/java/me/kudryavka/bluecon/SPPClient/SPPClientController.java
@@ -284,10 +284,12 @@ public class SPPClientController {
                     restartConnectionThread(mDevice);
                     interrupt();
                 }
-                synchronized (SPPClientController.this){
-                    connectionThread = null;
+                if (mSocket.isConnected()) {
+                    synchronized (SPPClientController.this){
+                        connectionThread = null;
+                    }
+                    connected(mSocket);
                 }
-                connected(mSocket);
             }
         }

@tsdogs
Copy link
Author

tsdogs commented Dec 11, 2017

well, at least in the demo. Still working on my project :-/

@tsdogs
Copy link
Author

tsdogs commented Dec 11, 2017

ok, there was a problem when running the demo and my app at the same time...
The change seems to solve the problem.

@tsdogs
Copy link
Author

tsdogs commented Dec 14, 2017

I though still have problems. If in the demo I select a device and then select the same device again the socket keeps on failing the connection.
I'm looking to find a better solution.

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

No branches or pull requests

1 participant