Saturday, November 13, 2010

You can't reuse ports within 60 seconds

As the title says, just a little gotchya I ran into. After having an open socket on a port, you can't bind another socket to that port for some specified timeout time afterwards. My test program for my tcpstream class worked fine, but if I tried to re-run it, I couldn't re-bind to the port I was using until a short while had passed. After an hour or so of trying to figure out why my socket wasn't closing, I finally found that it was actually Working As Intended(TM). It's fully explained in this post:

The short answer is:
"No, you may not re-use the port for the first 60 seconds
after a bound socket is closed (explicitly or because
the program exited)".

1 comment:

  1. setting SO_REUSEADDR for a socket will solve this problem AFAIK.

    ReplyDelete