How to use the websockets.exceptions.ConnectionClosedError 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 apiad / auditorium / auditorium / show.py View on Github external
def _do_ws_command(self, command):
        if command["type"] == "render":
            print("Rendering content")
            return dict(content=self.render())
        if command["type"] == "ping":
            print("Saying hello")
            return dict(msg="pong")
        elif command["type"] == "error":
            print("(!) %s" % command['msg'])
            raise websockets.exceptions.ConnectionClosedError(1006, command['msg'])
        else:
            print("Executing slide %s" % command["slide"])
            values = {}
            values[command["id"]] = command["value"]
            update = self.do_code(command["slide"], values)
            return update

        raise ValueError("Unknown command: %s", command["type"])
github machinezone / cobra / cobras / server / app.py View on Github external
connectionCount = len(app['connections'])
    state.log(f'(open) connections {connectionCount}')

    try:
        async for message in websocket:
            msgCount += 1
            await processCobraMessage(state, websocket, app, message)
            if not state.ok:
                raise Exception(state.error)

    except websockets.exceptions.ProtocolError as e:
        print(e)
        state.log('Protocol error')
    except websockets.exceptions.ConnectionClosedOK:
        state.log('Connection closed properly')
    except websockets.exceptions.ConnectionClosedError:
        state.log('Connection closed with an error')
    except Exception as e:
        print(e)
        print('Generic Exception caught in {}'.format(traceback.format_exc()))
    finally:
        del app['connections'][key]

        subCount = len(state.subscriptions)

        if subCount > 0:
            state.log('cancelling #{} subscriptions'.format(subCount))
        for val in state.subscriptions.values():
            task, role = val
            app['stats'].decrSubscriptionsBy(role, 1)
            task.cancel()
github machinezone / cobra / cobras / client / client.py View on Github external
logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except ConnectionRefusedError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except ConnectionResetError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except websockets.exceptions.ConnectionClosedOK as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except websockets.exceptions.ConnectionClosedError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except websockets.exceptions.InvalidMessage as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except OSError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except EOFError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except HandshakeException as e:
github crotwell / seisplotjs / docs / examples / viewobspy / serveobspy.py View on Github external
async def sendOneUser(self, user, message):
        try:
            await user.send(message)
        except websockets.exceptions.ConnectionClosedError as ee:
            logger.debug("ws conn was closed, removing user ")
            self.users.remove(user)
    async def initWS(self):
github spring-epfl / lightnion / lightnion / proxy / jobs.py View on Github external
Handler to receive a message from the client via the websocket.
        :param ws: websocket used to communicate with the client.
        :param channel: Channel correspondind to the client from which data is recieved.
        """

        while not ws.closed:
            try:
                cell = await ws.recv()

                self.cell_recv += 1
                logging.info('cell {} recv by wbskt: {}'.format(self.cell_recv, cell[:20].hex()))
                logging.debug('WsServ: Recieved cell from channel {}: {}... {} bytes.'.format(channel.cid, cell[:20], len(cell)))

                await self.channel_manager.link.schedule_to_send(cell, channel)

            except websockets.exceptions.ConnectionClosedError:
                logging.exception('Websocket connection closed.')
                return

            except websockets.exceptions.ConnectionClosedOK:
                logging.info('Websocket connection closed.')
                return
github machinezone / cobra / cobras / client / client.py View on Github external
logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except ConnectionRefusedError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except ConnectionResetError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except websockets.exceptions.ConnectionClosedOK as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except websockets.exceptions.ConnectionClosedError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except websockets.exceptions.InvalidMessage as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except OSError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except EOFError as e:
            logging.error(e)
            await asyncio.sleep(waitTime)
            pass
        except HandshakeException as e:
github Truth0906 / PTTLibrary / PTTLibrary / ConnectCore.py View on Github external
)
            else:
                Log.showValue(
                    Log.Level.DEBUG, [
                        i18n.SendMsg
                    ],
                    Msg
                )

            try:
                asyncio.get_event_loop().run_until_complete(
                    self._Core.send(Msg)
                )
            except asyncio.streams.IncompleteReadError:
                raise Exceptions.ConnectionClosed()
            except websockets.exceptions.ConnectionClosedError:
                raise Exceptions.ConnectionClosed()
            except RuntimeError:
                raise Exceptions.ConnectionClosed()
            except websockets.exceptions.ConnectionClosedOK:
                raise Exceptions.ConnectionClosed()

            if BreakDetectAfterSend:
                return BreakIndex

            Msg = ''
            ReceiveDataBuffer = bytes()

            StartTime = time.time()
            MidTime = time.time()
            while MidTime - StartTime < CurrentScreenTimeout:
                try: