Socket Bug : Connection status not update

Dextrosoft

Member
Licensed User
Longtime User
Hi,
I'm using a Socket Object in Network Library v1.01.

I can set up successfully a connection to a server.
Problem is that when the connection is broken afterwards, ie connection status is going from connected to unconnected again, ( eg Server process stopped, WIFI interruption) the socket.connected parameter stays True.

The idea is that with help of a timer I can test the "status" of the connection. If the connection would be broken, trying to reconnect...

The closest I got, was using a AsyncStream and sending a "Ping-Pong" command. The AsyncStream would throw an exception if the connection is broken. Problem is that I can't set up the same connection anymore.

I tried to close the broken connection first, to set a new initialize method.
The weird thing is that the socket report back the same old status.

Anyway in short...
Could the "connected" property be changed that it report the actual status ?

or could we have a new event reporting a change in connections status ?

Regards,
Wim
 

agraham

Expert
Licensed User
Longtime User
This may be an Android "feature". There seem to be other people out on the net reporting it and I found this quote, although I don't know how authoritative it is
SocketChannel.socket().isConnected() and SocketChannel.isConnected() return false before the socket is connected. Once the socket is connected they will return true, they will not revert to false for any reason.
 

Dextrosoft

Member
Licensed User
Longtime User
Hi,

Just to inform you... I was able to close and re-open a socket by calling the socket.initialise function after the socket.close.

Together with a 10 sec timer sending a ping-pong command to the server, it allows me to mimic the "auto-reconnect" function I was looking for.

Thanks for the feedback.

Small final question : Will the socket.initialise function have any memory impact ? In worst case I end up calling it every x seconds.

cheers,
Wim
 
Top