Browse files

Merge pull request #4 from mzweilin/master

Enabled the IPv6 features.
  • Loading branch information...
2 parents d4ca6e9 + 69761b7 commit 17fada1b4212e38a2be4b26a5fb8631b4f90185a @rep committed Mar 23, 2013
Showing with 6 additions and 1 deletion.
  1. +6 −1 evnet/__init__.py
View
7 evnet/__init__.py
@@ -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

0 comments on commit 17fada1

Please sign in to comment.