Skip to content

Commit

Permalink
Added support to binding IPv6 address. Added support to listening on …
Browse files Browse the repository at this point in the history
…dual-stack sockets <::>.
  • Loading branch information
= committed Oct 30, 2012
1 parent 48d55e6 commit 69761b7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion evnet/__init__.py
Expand Up @@ -66,8 +66,13 @@ def connectplain(host, port):
return PlainClientConnection((host,port))

def listensock(host='', port=0, backlog_limit=5):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# If you would like to accept dual-stack connections, please bind <::>.
ainfo = socket.getaddrinfo(host, 1, socket.AF_UNSPEC, socket.SOCK_STREAM)
addr_family = ainfo[0][0]
sock = socket.socket(addr_family, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# Set a compatible socket, in order to accept connections from both IPv4 and IPv6 nodes.
if addr_family == socket.AF_INET6: sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
sock.bind((host, port))
sock.listen(backlog_limit)
return sock
Expand Down

0 comments on commit 69761b7

Please sign in to comment.