Skip to content

Commit

Permalink
Added support for ipv6 in sync client (Fixes #39)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Oct 10, 2024
1 parent f194759 commit d4f05c7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/simple_websocket/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,21 @@ def __init__(self, url, subprotocols=None, headers=None,
elif isinstance(headers, list):
self.extra_headeers = headers

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection_args = None
for conn in socket.getaddrinfo(self.host, self.port): # pragma: no branch
if conn[1] == socket.SOCK_STREAM: # pragma: no branch
connection_args = conn
break
if connection_args is None: # pragma: no cover
raise ConnectionError()
sock = socket.socket(connection_args[0], connection_args[1],
connection_args[2])
if is_secure: # pragma: no cover
if ssl_context is None:
ssl_context = ssl.create_default_context(
purpose=ssl.Purpose.SERVER_AUTH)
sock = ssl_context.wrap_socket(sock, server_hostname=self.host)
sock.connect((self.host, self.port))
sock.connect(connection_args[4])
super().__init__(sock, connection_type=ConnectionType.CLIENT,
receive_bytes=receive_bytes,
ping_interval=ping_interval,
Expand Down

0 comments on commit d4f05c7

Please sign in to comment.