Skip to main content
gamedev.net
🔒 Locked

Removing Socket.Bind

Started by EnochDagor 2 replies 1.4k views
Original Post
EnochDagor
EnochDagor
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
Enoch DagorLead DeveloperDark Sky EntertainmentBeyond Protocol
Ozymandias42
Ozymandias42
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.
EnochDagor
EnochDagor
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...)
Enoch DagorLead DeveloperDark Sky EntertainmentBeyond Protocol
hplus0603
hplus0603
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.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.