16.01.2014 Views

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 24 ■ PROJECT 5: A VIRTUAL TEA PARTY 467<br />

and the user dilbert connected <strong>to</strong> the server using the command<br />

telnet localhost 5005<br />

Figure 24-1. A sample chat session<br />

Listing 24-6. A Slightly More Complicated Chat Server (chatserver.py)<br />

from asyncore import dispatcher<br />

from asynchat import async_chat<br />

import socket, asyncore<br />

PORT = 5005<br />

NAME = 'TestChat'<br />

class EndSession(Exception): pass<br />

class CommandHandler:<br />

"""<br />

Simple command handler similar <strong>to</strong> cmd.Cmd from the standard<br />

library.<br />

"""

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!