Android Question Socket + AsyncStreams detect connection loss

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone,
I'm trying to improve Modbus TCP library from @Walter95 that internally uses Socket and AsyncStreams
I was trying to add the _Connected and _Disconnected events.
I managed to get the first one (forwarding the Socket event) but I do not know how to detect a disconnection of the client from the server....

I implemented the _Terminated event from AsyncStreams but it does not seem to work properly... I saw it working after something like 5 minutes after disconnecting the server from the network.

Is there a reliable way to know if the connection has been terminated?

Thanks in advance

Edit: I Test several times and most of the times the event does not fire at all
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Important network example: [B4X] [B4XPages] Network + AsyncStreams + B4XSerializator

Is there a reliable way to know if the connection has been terminated?
Assuming that everything is implemented correctly, there are cases where the network adapter doesn't recognize the state correctly. You can usually solve it in the application layer. Send a "ping" request every second and if there is no response after 10 seconds, break the connection.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Important network example: [B4X] [B4XPages] Network + AsyncStreams + B4XSerializator


Assuming that everything is implemented correctly, there are cases where the network adapter doesn't recognize the state correctly. You can usually solve it in the application layer. Send a "ping" request every second and if there is no response after 10 seconds, break the connection.
Ok thanks Erel.
However I already correctly implemented the _Terminated event for the socket... Infact when i disconnect using the "Disconnect" button the event is fired… but if I unplug the cable, or the connection is interrupted it does nothing
 
Last edited:
Upvote 0
Top