Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a real-time chat with Python and websocket

I'm writing a python real-time chat feature embedded in a web app. I'm a little bit confused on the real time implementation. I need to push real time message to different users.

I plan to use websocket but I'm not quite sure how to save those sockets into an array so that once a user send a message to server, the server can find the related socket and push the message.

So any idea about this? Or what's the common way to implement real time chat feature?

Thanks in advance.

like image 226
mlin956 Avatar asked Jun 02 '15 18:06

mlin956


1 Answers

You need to use a websocket aware web server, like Tornado to handle websocket traffic. To multiplex chat messages between different chats and users, there are solutions like Redis and ZeroMQ that you can use for message multiplexing.

However, it sounds like you have zero experience and starting point, so starting with an working example is better approach. Please study existing real-time chat implementations for Python:

https://github.com/heroku-examples/python-websockets-chat

https://github.com/nellessen/Tornado-Redis-Chat

https://github.com/tornadoweb/tornado/blob/master/demos/websocket/chatdemo.py

http://ferretfarmer.net/2013/09/05/tutorial-real-time-chat-with-django-twisted-and-websockets-part-1/

like image 138
Mikko Ohtamaa Avatar answered Oct 04 '22 01:10

Mikko Ohtamaa