Chat system

Chris Armstrong punck at SpamIsBadPenguinPowered.com
Wed Mar 15 23:32:34 EST 2000


Okay, noted. Only thing is that the chat module itself shouldn't (well, wasn't
planned) to have anything to do with sockets. inetd handles connections
and just starts my game, and the chat system is just a plugin to my game..
Although I guess I could still use the select thing.. Maybe with named pipes?
(I don't know much about those.)
or maybe I'll just set up a socket server for the chat module that only gets
local connections, although I really don't want to do this.

In article <slrn8d0j27.27vf.cjc26 at bridget.mindriot.net>, cjc26 at nospam.cornell.edu (Cliff Crawford) wrote:
> You can do this using select() (in the "select" module :).  You pass
> select three lists of file descriptors that you're waiting to do
> something with.  One list is for files you're waiting to read from,
> another is for files you want to write to, and the third is for error
> conditions.  Select blocks until one or more of those file
> descriptors are actually ready, or an error occurs on the one of the
> files you are watching for errors.  You can also set a timeout if you
> need to.
> 
> So, for what you want to do, you would call select inside an infinite
> loop.  The arguments would be the socket you are listening to, and
> the file descriptor for stdin.  Thus either data coming in on the
> socket, or a user pressing a key, will cause select to return the
> appropriate file desc.; from there your program can figure out what
> to do next.  So you would do something like:
> 
> 	soc=socket.fileno()
> 	in=sys.stdin.fileno()
> 	while 1:
> 		r, w, e = select([soc, in], [], [soc, in])
> 		for fd in r:
> 			# process input
> 
> Also, there's the asyncore module, which is a higher-level interface
> to all of this.

-- 
Chris Armstrong
http://drol.sourceforge.net

Geek code version 3.12
GCS d? s:-- a--- C+++ UL++++>++++ P++ L+++ E--- W++ N+ o? K- w-- 
O-- !M V PS+(+++) PE? Y+(--) PGP(--) t+ 5 X+ R tv+ b+>++ DI+ D+++ 
G e- h!(--) r- y?
Go to www.geekcode.com to find out what on earth this is.




More information about the Python-list mailing list