chat server

Chris Liechti cliechti at gmx.net
Thu Mar 28 21:08:14 EST 2002


Henning Peters <pete at dexterslab.de> wrote in
news:B8C97068.C30E%pete at dexterslab.de: 
> hi pythonists,
> 
> i am planning to write a small chat server that uses select() in
> python. multiple clients should be able to connect and chat wih 
each
> other - like on a normal chatserver, just asynchronous...
> 
> my current problem is, that i have no clue how to implement the
> communication between the sockets (a chat message should be 
> directed to all other connected clients).

just maintain a list of client sockets. when you recveive data from 
one distribute it to the others in a for loop over the list.

its possible to add the server socket to the "possible readers" list 
of select so that you can accept new connections without problems.

done that been there - but i won't spoil your fun by sending my code 
;-) unless you relay want.

> is this possible to implement with select() or should it be better 
to
> use the good old fork() each time, a client connects and implement
> interprocess communication via pipelines or shared memory?!

There is also a threading module, i don't think you realy want 
separate processes. but it works fine with select.

> btw: does anybody knows a good documentation about select() and 
related
> themes - i've already read
> http://www.nightmare.com/medusa/programming.html. 

you may be interested in this too:
http://py-howto.sourceforge.net/sockets/sockets.html
 
> bye,
> henning peters
> 
> 



-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list