Android Question Socket Exception

QtechLab

Active Member
Licensed User
Longtime User
Hello everyone,

Who knows how to fix the following crash?
java.net.SocketException
in java.net.Socket.checkOpenAndCreate

Schermata 2017-01-13 alle 11.21.23.png


Thanks in advance
 

QtechLab

Active Member
Licensed User
Longtime User
I Reaqlly don't know where find it. I see these exceptions on Google Play developer panel
 
Upvote 0

QtechLab

Active Member
Licensed User
Longtime User
This is what i find about it.

java.lang.RuntimeException: java.net.SocketException: Socket is not connected
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: java.net.SocketException: Socket is not connected
at java.net.Socket.checkOpenAndCreate(Socket.java:671)
at java.net.Socket.getInputStream(Socket.java:361)
at anywheresoftware.b4a.objects.SocketWrapper.getInputStream(SocketWrapper.java:220)
at com.XXXXX.XXXXX.clscentrali_imx._isock_connected(clscentrali_imx.java:2066)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
 
Upvote 0

QtechLab

Active Member
Licensed User
Longtime User
My guess is that you are not checking whether the Successful parameter is true before getting the input stream.

This is the function in my app
B4X:
private Sub iSock_Connected (Successful As Boolean)
    If Successful = True Then
        timerData.Enabled = False
   
        If TimerConnect.IsInitialized Then
            TimerConnect.Enabled = False
        End If
       
        Dim TxBuffer() As Byte
        iStream.Initialize(iSock.InputStream, iSock.OutputStream, "iStream")

        Log("SOCKET CONNECTED")
       
        If CONNECTION_OK = False And USE_SERVER = True Then
            'REQ:ary(12) as byte
            Dim str As String = IMX.REQID & IMX.GetPasswordConnessione
            Log("Invio REQID e CheckPSW")
            Dim tmp() As Byte = str.GetBytes("ASCII")
            iStream.Write(str.GetBytes("ASCII"))
        Else
            GetXpKeys
        End If
       
    Else
        'Se errore di connessione...
        TimerConnect_Tick
        Log("iSock_Connected = " & Successful)
    End If
   
End Sub
 
Upvote 0

QtechLab

Active Member
Licensed User
Longtime User
I'm connecting to a simple server, i don't know why it give me back that error. Personally i never got one with my Nexus 5X. Maybe this problem comes up with other vendor custom devices (most of all in Android 6.X)
 
Upvote 0
Top