def create_socket():
 if has_ipv6:
  sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
  if hasattr(socket, u'IPPROTO_IPV6'):
   sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
  elif (sys.platform == u'win32'):
   sock.setsockopt(41, 27, 0)
 else:
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 return sock

def create_socket ( ) : if has_ipv6 : sock = socket . socket ( socket . AF_INET6 , socket . SOCK_STREAM ) if hasattr ( socket , u'IPPROTO_IPV6' ) : sock . setsockopt ( socket . IPPROTO_IPV6 , socket . IPV6_V6ONLY , 0 ) elif ( sys . platform == u'win32' ) : sock . setsockopt ( 41 , 27 , 0 ) else : sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) return sock
create a tcp socket with or without ipv6 depending on system support .