Hi,
Here is the issue I am having. I wrote a TCP client program using TM4C129E launchpad and NDK and I tested it with a program called Socket Test and Packet Sender and it works.
When the Server (Socket Test or Packet Sender) disconnects first, my TCP client is able to call close() successfully. Whenever I reconnect to the server, I am able to do it with no problems. However, when the TCP client (launchpad) calls close() first, I am still able to disconnect successfully because close would not return an error. I noticed the server disconnects too (at least from what I am seeing based on the gui but I have no idea what goes on under the hood). Whenever I reconnect, it fails for some period of time and then eventually I am able to reconnect again. But I have to wait for sometime. During the time that reconnection fails, I noticed an error in bind. and using fdError, I get error 48 which I think is EADDRINUSE. So what I did was call setsockopt and enable SO_REUSEPORT. This eliminated the error in bind. However, now I get an error when calling connect(). I called fdError and it's still 48. How is this possible? I have closed the client successfully and the server seems to have closed the socket as well. I did some digging and found out about TIME_WAIT. How do you change the TIME_WAIT here? I'm not sure if this is the solution.
Since I do not have a complete control of the server, I decided to do another test. I got another launchpad and set it up as a TCP server. Now I know I have complete control of the close() functioning the server side. When I call close() on the server side, close returns successful on server and client also calls close successfully. Reconnection is not a problem. However, when I initiate disconnect on client side(call close here first), I see that close is called successfully on client and even on the server. Looks like, in both sides, socket is closed. However, I am not able to reconnect the client right away. I need to wait for some time before I am able to connect. I am experiencing the same issue as explained above. I keep on getting error 48 for a certain amount of time when calling bind, or when calling connect if I have set SO_REUSEPORT.
Any solution to this matter?
Thanks.
AJ