Socket.close not really resulting in disconnect...
Hello,
I have used the tutorials and forum examples to play around with Networking, and like others, I've noticed that socket.close and/or socketio.close does not kill the connection to my server (...which is running on a PC). The only way to receive a FD_CLOSE message from WinSock is to kill the android app, and I believe I've read a post that describes the same experience. I don't think a solution was presented, but I did find an article (Tal's tech recipes » Closing Android socket and quoted below) that talks about this issue in Java, and the solution is to call Socket.shutdownInput. Can this be implemented in Basic4Android? What are your thoughts on the subject, and does it represent a solution?
"Closing Android socket
Assume we have a Socket that is connected to a server. Usually, we will use a secondary thread to read from the socket in a blocking connection.
If the user want to terminate the connection, in Java, we can call socket.close(). But not in Android (well, we can, but it will do nothing). While the thread is still alive and waiting, close() will not be executed and the connection will remain active. So, what can be done?
One way is to terminate the thread. This is obviously not a very good way, and denied the thread from executing its final code correctly.
The second and the right one, is simply to call Socket.shutdownInput() method. This will create a disconnection for the waiting thread, the thread will die according to plan and your application will run just fine!"
Hello,
I have used the tutorials and forum examples to play around with Networking, and like others, I've noticed that socket.close and/or socketio.close does not kill the connection to my server (...which is running on a PC). The only way to receive a FD_CLOSE message from WinSock is to kill the android app, and I believe I've read a post that describes the same experience. I don't think a solution was presented, but I did find an article (Tal's tech recipes » Closing Android socket and quoted below) that talks about this issue in Java, and the solution is to call Socket.shutdownInput. Can this be implemented in Basic4Android? What are your thoughts on the subject, and does it represent a solution?
"Closing Android socket
Assume we have a Socket that is connected to a server. Usually, we will use a secondary thread to read from the socket in a blocking connection.
If the user want to terminate the connection, in Java, we can call socket.close(). But not in Android (well, we can, but it will do nothing). While the thread is still alive and waiting, close() will not be executed and the connection will remain active. So, what can be done?
One way is to terminate the thread. This is obviously not a very good way, and denied the thread from executing its final code correctly.
The second and the right one, is simply to call Socket.shutdownInput() method. This will create a disconnection for the waiting thread, the thread will die according to plan and your application will run just fine!"
Last edited: