I have an issue with sockets. I’m creating a socket between my computer and my phone to send messages. When I close the server or the client it sends a FIN packet and it stays in the FIN_WAIT2 state for like a minute. However, the other side get stuck in the CLOSE_WAIT state, apparently incapable of closing the socket. I reckon that sockets should be closed instantly, so maybe I should somehow implement a code in the client that closes the socket when the server wants to close it and vice versa. How can I do that?
Share
You need to close both ends of a socket channel.
If the server closes a connection to a client, the client needs to close the connection on the client-end, for the last
FINpacket to be transmitted (from client to server). This will trigger the last state transition in the TCP state machine.