AsyncStreams - Terminated

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I am connecting to a TCP device using AsyncStreams and I have a sub called 'Streams_Terminated'.

I can connect to my device fine and send messages to it and get reply's fine, but my issue is that if my TCP device disconnects and looses connection to my app how can I make my app know that the connection has been lost?

I have used the code below but the sub 'AStreams_socket_Terminated' never gets called when my TCP device disconnects.

B4X:
Sub Process_Globals
    Dim AStreams_socket As AsyncStreams
End Sub

Sub AStreams_socket_Error
    Log(LastException.Message)
End Sub

Sub AStreams_socket_Terminated
    Log("terminated")
End Sub

Is there another way to check if my device has lost connection my app?
 

mc73

Well-Known Member
Licensed User
Longtime User
A way is to periodically ping your server. If no response arrives in a certain period, you'll get a strems_error.
You can also have a look at how b4a bridge works (its source code). You'll find a disconnect timer, which after 10 ticks closes the connection (meaning no activity was found, which would reset the timer, as far as I understood).
 
Upvote 0
Top