remote client, possible port exhaustion? networking

I'm working on a remote client program that gets data from a serial port sensor and sends it to a server. The sensor will output 1 time each second. My Windows client runs fine untill the remote client PC has a loss of internet connectivity. All of the remote PC's are on someone's wireless high speed internet connection.
What the client should do:
1: When attempting a new socket always check to see the SOCKET is flagged INVALID, if not then close it. Always wait 5 seconds then establish a local socket and call a connect function to the server IP and port. If successful continue to use this port untill a socket error is detected. After the initial server login response the client never expects to see any return data from the server, it simply sends data out.
2: TCP thread will call a check connection function each loop. It calls a Select call on the socket in use. If marked readable the call read function. If 0 bytes returned then the server closed the connection so call closesocket, if socket error then call closesocket, else if no error move on assuming the connection is stable.
3: Each time data come in from the serial port, check the message and then send to the sever.

I have modified the Windows registry to change the Timed_Wait to 1 second instead of 4 minutes as is Windows default.
My application sets socket option tcp nodelay to 1 and dontlinger to 0

I've been trying to track down the fault that causes the inability to auto reconnect. I was at one of the remote clients the other day, while it showed internet access the program was unable to create a new connection. Closing the application and restarting a new instance of it got it going again.

Question: what happens when Windows works an application up through to the max available port number? Does it start over at the lower number on the next attempt or does it just stop?

The other day I did not think about using netstat to check the port status. I'm trying to run a PC though untill it stops today while I type this. The one thing I noticed is how every disconnect that I force to happen causes the current port used by the application to increment.

Any other ideas what may be going on?
It is not impossible (though rather unlikely) that ports exhausts:

https://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx


Check whether you application inadequately opens port and doesn't close them.

More likely is that the program is in a condition where opening a port is not possible due to some undefined behaviour such as accessing invalid data.
Topic archived. No new replies allowed.