[vox-tech] Chat program in 100 lines of code!

Bill Broadley bill at broadley.org
Wed Oct 20 20:03:51 PDT 2010


Very cool, nice walk though.  Kudos to Brian for a great post.

Posts like Brian's definitely lower the barrier to entry.  I enjoy
cut/paste type intros so you can tinker with something quickly and
painlessly.

I've been tinkering with similar with Python's twisted library.  I
figured I'd do a similar intro for a chat client using the python
twisted library.

1) Install twisted (apt-get/yum install python-twisted) or very similar
2) mkdir chat_server
3) go to
http://www.koders.com/python/fidD65298C63F7F8C0BFA09681B5981427544C470A9.aspx?s=wxpython
   And click download [1]
4) twistd -y chatserver.py
5) in two windows type telnet localhost 1025
6) binary package = 1MB or so (vs 44MB for ActiveMQ)
7) python chat server = 12MB resident (vs 200MB for ActiveMQ)

The differences I noted:
* 37 lines instead of 100 ish
* No nickname prefixes
* No editing of files or setting environment variables.
* Twisted is a library (to enable clients or servers) not a network
  service/daemon (like ActiveMQ).


For a more complete example I tinkered with ampchat:
1) apt-get install python-twisted
2) hg clone http://ripton.net/hg/ampchat
3) cd ampchat
4) python chatserver.py
5) in new window: python chatserver.py  file -> connect login: a password: a
6) in new window: python chatserver.py  file -> connect login: b password: b

The differences I noted:
* 580 lines instead of 100 ish
* client <-> server architecture
* GUI
* Usernames and passwords
* Shows who is connected.
* No editing of files or setting environment variables.
* can send messages to everyone or any subset of users.

Has anyone here written anything non-trivial in twisted?  ActiveMQ?

For the curious my interest in this is wanting to implement a simple
put/get encrypted protocol for binary blobs for a p2p backup system I'm
writing.

[1] Authoritative site
http://twistedsphinx.funsize.net/projects/core/examples/index.html has a
broken link for chatserver.py.  Also available in the twisted source
available at twistmatrix.com site.



More information about the vox-tech mailing list