Geo
Geo

Reputation: 96987

Is windows's setsockopt broken?

I want to be able to reuse some ports, and that's why I'm using setsockopt on my sockets, with the following code:

sock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)

However, this doesn't really work. I'm not getting a bind error either, but the server socket just isn't responding (it seems to start , but if I try to connect to it, it doesn't enter the select loop). This behaviour appears if the script ended unexpectedly, and if I change the port the server is listening on, everything works again. Can you provide some advice?

EDIT: I renamed the socket to sock. It was just a name I chose for this code snippet.

Upvotes: 2

Views: 2253

Answers (2)

paleozogt
paleozogt

Reputation: 6573

It appears that SO_REUSEADDR has different semantics on Windows vs Unix.

See this msdn article (particularly the chart below "Using SO_EXCLUSIVEADDRUSE") and this unix faq.

Also, see this python bug discussion, this twisted bug discussion, and this list of differences between Windows and Unix sockets.

Upvotes: 3

SilentGhost
SilentGhost

Reputation: 320039

setsockopt is a method of a socket object. module socket doesn't have a setsockopt attribute.

Upvotes: 1

Related Questions