(self, url, protocols=None, extensions=None, heartbeat_freq=None)
A websocket client that implements :rfc:`6455` and provides a simple
        interface to communicate with a websocket server.

        This class works on its own but will block if not run in
        its own thread.

        When an instance of this class is created, a :py:mod:`socket`
        is created with the nagle's algorithm disabled and with
        the capacity to reuse a port that was just used.

        The address of the server will be extracted from the given
        websocket url.

        The websocket key is randomly generated, reset the
        `key` attribute if you want to provide yours.
A websocket client that implements :rfc:`6455` and provides a simple
        interface to communicate with a websocket server.
A websocket client that implements : rfc : 6455 and provides a simple interface to communicate with a websocket server .
def __init__(self, url, protocols=None, extensions=None, heartbeat_freq=None):
        """
        A websocket client that implements :rfc:`6455` and provides a simple
        interface to communicate with a websocket server.

        This class works on its own but will block if not run in
        its own thread.

        When an instance of this class is created, a :py:mod:`socket`
        is created with the nagle's algorithm disabled and with
        the capacity to reuse a port that was just used.

        The address of the server will be extracted from the given
        websocket url.

        The websocket key is randomly generated, reset the
        `key` attribute if you want to provide yours.

        """
        self.url = url
        self.host = None
        self.scheme = None
        self.port = None
        self.resource = None

        self._parse_url()

        # Let's handle IPv4 and IPv6 addresses
        # Simplified from CherryPy's code
        try:
            family, socktype, proto, canonname, sa = socket.getaddrinfo(self.host, self.port,
                                                                        socket.AF_UNSPEC,
                                                                        socket.SOCK_STREAM,
                                                                        0, socket.AI_PASSIVE)[0]
        except socket.gaierror:
            family = socket.AF_INET
            if self.host.startswith('::'):
                family = socket.AF_INET6

            socktype = socket.SOCK_STREAM
            proto = 0
            canonname = ""
            sa = (self.host, self.port, 0, 0)

        sock = socket.socket(family, socktype, proto)
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        if hasattr(socket, 'AF_INET6') and family == socket.AF_INET6 and \
          self.host.startswith('::'):
            try:
                sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
            except (AttributeError, socket.error):
                pass

        WebSocket.__init__(self, sock, protocols=protocols,
                           extensions=extensions,
                           heartbeat_freq=heartbeat_freq)

        self.stream.always_mask = True
        self.stream.expect_masking = False
        self.key = b64encode(os.urandom(16))
def __init__ ( self , url , protocols = None , extensions = None , heartbeat_freq = None ) : self . url = url self . host = None self . scheme = None self . port = None self . resource = None self . _parse_url ( ) # Let's handle IPv4 and IPv6 addresses # Simplified from CherryPy's code try : family , socktype , proto , canonname , sa = socket . getaddrinfo ( self . host , self . port , socket . AF_UNSPEC , socket . SOCK_STREAM , 0 , socket . AI_PASSIVE ) [ 0 ] except socket . gaierror : family = socket . AF_INET if self . host . startswith ( '::' ) : family = socket . AF_INET6 socktype = socket . SOCK_STREAM proto = 0 canonname = "" sa = ( self . host , self . port , 0 , 0 ) sock = socket . socket ( family , socktype , proto ) sock . setsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY , 1 ) sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) if hasattr ( socket , 'AF_INET6' ) and family == socket . AF_INET6 and self . host . startswith ( '::' ) : try : sock . setsockopt ( socket . IPPROTO_IPV6 , socket . IPV6_V6ONLY , 0 ) except ( AttributeError , socket . error ) : pass WebSocket . __init__ ( self , sock , protocols = protocols , extensions = extensions , heartbeat_freq = heartbeat_freq ) self . stream . always_mask = True self . stream . expect_masking = False self . key = b64encode ( os . urandom ( 16 ) )