Jump to content
  • Advertisement
Sign in to follow this  
EnochDagor

Removing Socket.Bind

This topic is 4336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have a TCP socket connection. The client does a Socket.Bind() call to the local IP address and the specific port number I need to use before calling Socket.Connect(). This works great and I have no problems with my firewall/router.... However, the problem comes in when the client disconnects. The client disconnects and closes the process... There seems to be about a 60-120 second period of time after the process closes that Windows thinks that the socket is still bound. During this time, the client won't connect (for obvious reasons). Is there a way to forcefully unbind the socket? -E

Share this post


Link to post
Share on other sites
Advertisement
I have an unrelated question. Why does your client need to use a specific port number? I understand why the client might want to set its local IP address, but why the port? Is it for some sort of complex network security reason, like the firewall requiring an outgoing communication from a specific port on a specific machine? That's weird.

Share this post


Link to post
Share on other sites
Older code... I might not need it anymore... it worked for my machine so I'm anxious to see how external users can use it. I'll post back here if I still require it (and the reason behind it).

Otherwise, unless I post back here, consider this a non-issue. (would explain why I can't find help on it anywhere...)

Share this post


Link to post
Share on other sites
The reason it takes a while to be able to re-bind to a port is that the TCP protocol specifies that the address be non-usable for some amount of time after shutdown, to avoid delayed packets on the network confusing a potential new connection. You can turn this off with SO_REUSEADDR, but a better choice is to not bind the socket on the client at all -- it won't need a specific port, and binding means you can't run more than one client at a time on the same machine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!