Code sample from my MemPy presentation on December 19, 2011.
Please keep in mind that this code is not production worthy and is VERY inefficient. For clarity, I have not made any attempt to optimize. Also, I abandoned good coding practice to get as many features into the demo as possible.
There is a bug that is left as an exercise to the reader. When starting a new IM session, the user who starts it must refresh their page before any messages can be sent or received.
Slides are at Google Docs