On Sun, 19 Sep 2010 18:42:51 +1200, Lawrence D'Oliveiro wrote: >>>> That's why Stevens recommends that all TCP servers use the >>>> SO_REUSEADDR socket option. >>> >>> I don’t think I’ve ever used that. It seems to defeat a safety mechanism >>> which was put in for a reason. >> >> It was put in for the benefit of clients, to prevent them from selecting >> a port which they won't be able to use. > > But clients typically don’t care what port they use—they let the > system pick a port for them, so this kind of option is unnecessary.
If they use an ephemeral port, the kernel won't pick a port which has any connections in the TIME_WAIT state. However, some clients choose their own source ports. E.g. rlogin/rsh use privileged (low-numbered) ports, and you can't get the kernel to choose a random privileged port for you. If you're writing a server which listens on a known port, you *should* be using SO_REUSEADDR to avoid unnecessary delays in start-up. The kernel will automatically reject packets relating to stale connections, and your server should be accepting any new connections ASAP. -- http://mail.python.org/mailman/listinfo/python-list