Using a Python client to test Tornado WebSockets

In my last article I showed you how to how to use WebSockets in a very minimal code fashion using Tornado and Python. Today, I’ll show you a very easy way to build a Python client and test out your WebSocket projects using a library called: websocket-client.

To install the websocket-client simply do the following:

$ pip install websocket-client

You also will need Tornado:

$ pip install tornado

If you haven’t worked through my previous article anyou may want to get that project up and running first to see how the basics work. We are going to borrow the code from the ws_app.py file which is listed below and modified for this article:

If you run each file individually (make sure to start the server portion first) you can see the communication go back and forth. You can see how you can build Python WebSocket clients to test out your WebSocket applications without having to use HTML/JavaScript pages all the time. Sometimes this is all you will need, other times you will need more but its always good to have an extra tool in your belt just in case.