How to use the websockets.client.connect function in websockets

To help you get started, we’ve selected a few websockets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simonwittber / netwrok-server / tests / core.py View on Github external
def conn():
    ws = yield from websockets.client.connect('ws://0.0.0.0:8765')
    return ws
github OpenMined / PySyft / syft / core / workers / websocket.py View on Github external
)

        self.is_asyncronous = True
        self.hook = hook
        self.hostname = hostname
        self.port = port
        self.uri = "ws://" + self.hostname + ":" + str(self.port)

        self.max_connections = max_connections
        self.is_pointer = is_pointer

        if self.is_pointer:
            if self.verbose:
                print("Attaching Pointer to WebSocket Worker....")
            self.serversocket = None
            clientsocket = websockets.client.connect(self.uri)
            self.clientsocket = clientsocket

        else:
            if self.verbose:
                print("Starting a Websocket Worker....")
                if not is_client_worker or self.is_pointer:
                    print("Ready to recieve commands....")
                    self.serversocket = websockets.serve(
                        self._server_socket_listener, self.hostname, self.port
                    )
                    print("Server Socket has been initialized")
                    asyncio.get_event_loop().run_until_complete(self.serversocket)
                    asyncio.get_event_loop().run_forever()

                else:
                    print("Ready...")
github mixer / interactive-python / interactive_python / connection.py View on Github external
def __init__(self, address=None, authorization=None,
                 project_version_id=None, project_sharecode=None,
                 extra_headers={}, loop=asyncio.get_event_loop(), socket=None,
                 protocol_version="2.0"):

        if authorization is not None:
            extra_headers['Authorization'] = authorization
        if project_version_id is not None:
            extra_headers['X-Interactive-Version'] = project_version_id
        if project_sharecode is not None:
            extra_headers['X-Interactive-Sharecode'] = project_sharecode
        extra_headers['X-Protocol-Version'] = protocol_version

        self._socket_or_connector = socket or websockets.client.connect(
            address, loop=loop, extra_headers=extra_headers)
        self._socket = None

        self._loop = loop
        self._encoding = TextEncoding()
        self._awaiting_replies = {}
        self._call_counter = 0
        self._last_sequence_number = 0

        self._recv_queue = collections.deque()
        self._recv_await = None
        self._recv_task = None
github ontio / ontology-python-sdk / ontology / network / websocket.py View on Github external
async def connect(self):
        try:
            self.__ws_client = await client.connect(self.__url)
        except ConnectionAbortedError as e:
            raise SDKException(ErrorCode.other_error(e.args[1])) from None
        except socket.gaierror as e:
            raise SDKException(ErrorCode.other_error(e.args[1])) from None
github shrimpy-dev / shrimpy-python / shrimpy / shrimpy_ws_client.py View on Github external
async def _connect(self):
        '''
            Handle connecting to shrimpy websocket server
        '''
        url = self.base_url
        if (self.token):
            url = self.base_url + "?token=" + self.token

        self.connection = await websockets.client.connect(url)
        if (self.connection is None) or (not self.connection.open):
            raise ConnectionFailureException('Failed to start the connection. Please reconnect.')

        self.is_closed = False