Websocket Chat

In order to get familiar with Websockets, I decided to make a very basic client and server chat system. The client was implemented as a web page, and the server was written in Python. The web page connects to the server through a websocket. The server code was later used for implementing the web-based display system in the Text Editor Tournament software.

Click on an image to enlarge.

The Python server follows the Websocket protocol in order to successfully communicate with the web page. The protocol begins with a handshake, where a websocket key is sent by the client (the web page), and the server replies with a hash value derived from the provided key. Then, the server can send and receive messages to and from the client.

The client side was much easier to implement. A simple HTML web page with some Javascript code is all it takes to get a Websocket client running.

The Python server code helped with creating the Text Editor Tournament software, which used Websockets to send messages to the overhead web-based display. Another potential use could be for implementing an online multiplayer mode in Cosmos Fight in the future.

Back to Top