socktools.examples.ws_dumper

To test this, connect with wscat to localhost and send properly formatted JSON messages.

By default, this example binds to localhost on port 31337 and uses json_mixin to parse messages.

I suggest using wscat to test it, open 2 terminals and copy the below:

$ python -m socktools.examples.ws_dumper
hit ctrl-c to quit
(18720) wsgi starting up on http://127.0.0.1:31337

After running the server, use wscat to send a test message:

$ wscat -c ws://localhost:31337
connected (press CTRL+C to quit)
> [0, "test"]

You should see the message dumped by the server:

(18720) accepted ('127.0.0.1', 45150)
Got raw data: [0, "test"]
Got message type 0 from 127.0.0.1:45150: test
Putting parsed message type 0 from 127.0.0.1:45150 on queue: test

Note

This example uses eventlet’s WSGI server, this is fine for testing but should NOT be used for production

class socktools.examples.ws_dumper.WSDumperProtocol(bind=None, connect=None, handlers={}, timeout=10, tick_interval=0.25, sock=None, meta_sock=None, logger=None, no_async=False)[source]

Bases: socktools.json_mixin.JSONParseMixin, socktools.wsgi_websocket_sock.WSGIWebsocketSock

Websocket dumper

Simply dumps every received message to stdout, messages are JSON lists of (msg_type,msg_data).

handle_all(from_addr, msg_type, msg_data)[source]