TCP Connected Event does not fire on Remote Server disconnect

teiterryd

New Member
Licensed User
Longtime User
How can one detect when a remote Server connection on a TCP Socket is dropped (or closed). To quote the documentation in the Android Network Tutorial:
"The Connected event is raised when the connection is ready or if it failed".

A.) However, the event is only fired when the socket connects.
B.) Socket1.Connected remains true even though the remote Server disconnects.

Whithout having an indication of the true connection state the program keeps sending data to the disconnected remote Server creating an exception at some point.

All suggestions would be appreciated.

B4A is so powerful! I love what we can do with it. Thanks B4A Team!

TeiTerryd
 

teiterryd

New Member
Licensed User
Longtime User
Hello Team:

Still having problems detecting the connection state from a TCP Client connection to a remote Server.


1. When I create a Client socket and send data to a remote Server - it works well – till the Server for whatever reason disconnects or goes offline. Then the client application is NOT notified that it has gone offline – unless the Server comes back online and then a java peer disconnect error is displayed. Then the AsyncStreams _Error handler is invoked.

If a AsyncStreams_Terminate handler is defined it never gets called. Is there a handler for AsyncStreams called _Terminate?

2. If the Server is not online when I try and connect then a Java exception is eventually thrown although I have wrapped the Connect in a try catch! A toast message appears on the Android screen despite the try catch and the catch is never executed. Not good for the user to see such messages. Great for debugging though.

If the remote Server goes offline the app will still pump data to it with stream write - without an error - ad infinitum.

The socket Connected property does not reflect the true status of the connection – After initially connecting it remains true!


Ideally:

If the remote server is not initially online then B4A client socket should throw an exception that can be caught with a try catch or return a value from Connect that says it is not possible. Java error messages should not appear if there is a try catch.

If the server is initially online and then goes offline B4A should either throw an exception that can be caught by the async error handler on the async write or by a try catch on the write. Or the socket can have an error handler or its Connected property should reflect the true nature of the connection.


Thank you for looking at this!

TeiTerryd
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Erel,
I am having the exact same problem as teiterryd.
  • if there is no server when app comes up, no problem, success in the connected is false
  • Server comes up, connection works, success is true
  • runs just fine
  • Server goes down
  • Success STAYS TRUE ad-infinitum
    • I do have Astreams_error and Astreams_Terminated events
    • They do fire
    • I do dimension the Socket and Astreams when those events fire
  • Socket_connected does fire and it still shows successful, ad-infinitum
  • After a dozen iterations or so, I get an Astreams_error, but it still thinks we are connected.
  • It continues to show successful within the connected event.
Your insights and advice on this will be greatly appreciated.
Rusty
 
Upvote 0
Top