Android Question After AStreams.Close and Socket1.Close the Connection is still alive

GvD

Member
Licensed User
i tried your first example with aStreams and an esp8266 sending data through
"client.connect"; "client.println(...)"; and "client.stop();".
It works fine. The mobile receives all data.
But when i close the app - the connection still stays alive.
After starting the app again - it crashes and the connection is closed.
Now starting the app - all ok.
I don't use toastmessages ...
B4X:
Sub Activity_Pause(UserClosed As Boolean)
    If UserClosed Then
        Log("closing")
        AStreams.Close
        Socket1.Close
    End If
End Sub
This is not enough to end the connection?


here a part of the log after crash:

B4X:
** Activity (main) Create, isFirst = false **
running waiting messages (1)
** Activity (main) Resume **
ON
AStreams_Terminated
main_astreams_terminated (java line: 413)
java.lang.RuntimeException: Object should first be initialized (Exception).
   at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
   at anywheresoftware.b4a.objects.B4AException.getMessage(B4AException.java:21)
   at b4a.GvDIT_SOS.main._astreams_terminated(main.java:413)
   at java.lang.reflect.Method.invoke(Native Method)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
   at anywheresoftware.b4a.BA$2.run(BA.java:365)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:158)
   at android.app.ActivityThread.main(ActivityThread.java:7224)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

sorry about my english ...
anyone know this problem? and can tell me the solution?
 

GvD

Member
Licensed User
... after sleeping i tryed the newer example from B4A_Network.zip... same result: receiving message is ok but after ending the app the connection stayes alive :(
 

GvD

Member
Licensed User
sorry - but no
- the mobile has to act as a server ( receiving messages )
- in the 2. Version of your example a service is used. The only change i'd done is to change from
B4X:
Private Sub ListenForConnections
    Do While working
        server.Listen
        Wait For Server_NewConnection (Successful As Boolean, NewSocket As Socket)
        If Successful Then
            CloseExistingConnection
            client = NewSocket
            'astream.InitializePrefix(client.InputStream, False, client.OutputStream, "astream")
            astream.Initialize(client.InputStream, client.OutputStream, "astream")
            UpdateState(True)
        End If
    Loop
End Sub
:(

and
B4X:
Sub Activity_Pause (UserClosed As Boolean)
    CallSub(Starter, "Disconnect")
End Sub
when i kill the app in adroid ( version 6.0.1 ) - the connection is closed immediately
 
Last edited:

GvD

Member
Licensed User
I can only guess that you are somehow making multiple connections. Calling Socket.Close should close the last socket created.
hmmm - that's possible... the sender acts sometimes every 3 seconds and close this connection after sending...
-> is there a possibility to close all connections with one call?
 
Top