[Twisted-Python] explanation of the chatserver.py example

Christopher Armstrong radix at twistedmatrix.com
Fri Apr 16 00:35:41 EDT 2004

George Patterson wrote:
> I have trying to write a chat server that will selectively send out
> messages to some clients. Anyway, looking around for a framework to
> start from and learn more about Python and other modules I stumbled
> upon chatserver.py twisted.sourceforge.net
> If Bob, Jane and Joe are chatting to each other, and Bob sends a
> string of characters to Jane as a private message, how would I loop
> through the lineReceived definition for Jane's client ID or IP
> address or something unique to Jane's connection.
> I want to change def lineReceived to something like

 > def lineReceived(self, line):
 >     print "received", repr(line)
 >     for c in self.factory.clients:
 > 	if c.id==required_id:
 > 	# ^-- I know this is not valid code
 > 	    c.message("Privmsg". line)
 > 	#end if
 >     #end for

When the client first connects, the protocol should be in the "waiting 
for identifying information" state. The client should send identifying 
information. Store that information on the protocal instance, and then 
let the client chat as usual.

That should be all you need.

  Twisted | Christopher Armstrong: International Man of Twistery
   Radix  |          Release Manager,  Twisted Project
---------+           http://radix.twistedmatrix.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20040416/0eedc7ae/attachment.pgp 

More information about the Twisted-Python mailing list