6

I am working on a homework project for a Networking class where we have to build a simple web based chat server in either C/C++ or Python. I chose Python because I thought it would be an easier language to implement the project in. We can use any material we find on the web, because it most likely won't have all the functionality that the project requires. In fact, the professor actually encouraged us to use material from the web including tutorials. He's not testing us on our ability to code rather our ability to implement networking code, and whether or not we fully understand the processes involved.

The project must handle multiple clients, and must be able to support multiple browsers, chrome, firefox, etc. A user needs to be able to type in an IP Address and a Port in the browser to connect. I just can't find any material to work with. I have found a little in C but nothing in Python.

Does anyone know of any complete tutorials out there? There are plenty for client/server command-based chats, but no browser based chats.

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
user1174834
  • 239
  • 3
  • 7
  • 14

2 Answers2

4

You can look at using TornadIO. Its a python implementation of Socket.io, for Tornado, Tornado is an event-driven python web server.

https://github.com/MrJoes/tornadio2

http://www.tornadoweb.org/

Socket.io is a cross-browser solution to socket/socket-like connections from the web client to the server. This will pretty much give you all the tools you need to do a chat server since it supports pub-sub subscriptions and messages. The nice thing about using socket.io for your purposes is that it tries a number of transports in order to ensure that new and old browsers can all communicate: Websocket, Flashsocket, xhr polling, jsonp, htmlfile. They all are attempted and used in a way that looks the same to the client.

Tornadio2 is the newer version that is compatible with the newer Socket.io 0.7+. This version added a lot of features that broke compatibility with 0.6. However, the original TornadIO contains a chatroom example which you could review and translate pretty easily to the newer version to get you started:

https://github.com/MrJoes/tornadio/tree/master/examples/chatroom

jdi
  • 90,542
  • 19
  • 167
  • 203
  • @jdi I know this a somewhat old post, but nevertheless: What are your thoughts on how one would store added messages to a database using this `tornadoio`? Would I have to incorporate the threading or multiprocessing module and have multiple processes – one for chat, one for db querying? Or is there a smoother way to do this that you see? – Friendly King Apr 03 '13 at 02:06
  • @JohnZ: I would just say go the route of having a worker thread blocking on a `queue.get` and when it receives a message it will add it to the database. That way you can throw a message in the queue from another thread and not block anything. – jdi Apr 03 '13 at 07:40
1

As far as I can understand, the home work given is let people gets hands on activity with network programming. So might take a look at www.twistedmatrix.com, few example use case of twisted
Chat comet site using python and twisted,
http://lists.canonical.org/pipermail/kragen-hacks/2005-April/000409.html,
http://code.google.com/p/twisted-chat-example/.

This one uses plain socket programming http://code.activestate.com/recipes/531824-chat-server-client-using-selectselect/,
http://ankurs.com/2008/05/creating-a-simple-chat-application-with-python/.

This one is based on gevent.

For simple chat room emulation without use of socket programming, here is the example gummi.

A real life use case at sourceforge.

Community
  • 1
  • 1
Kracekumar
  • 19,457
  • 10
  • 47
  • 56