kragen at dnaco.net
Thu Mar 16 04:07:14 CET 2000
In article <EoSz4.206$vb.113 at newsfeed.slurp.net>,
Chris Armstrong <punck at SpamIsBadPenguinPowered.com> wrote:
>So to make the problem simple: I just need to get a bunch of the
>same program running on the same box to do IRC-like chat. I know
>things like ytalk do this, but I figured I'd post my problem here before
>messing with some C code that I don't understand.
>I've thought about having a file that
>is written to and is read by all clients, but this is *really* inefficient.
>Another thing about the chat system: I need for it to be able to constantly
>stream in new content while still being able to type in your message and
>send it whenever you want. I know some programs like IRC clients do
>this without having two processes (one for the streaming content and
>one for the input). Oh, and one more thing, this'll all be using curses,
>if it matters.
You want event-loop-based multiplexing. I think there's something
called 'asyncore' in the Python distribution.
The event-loop idea is that your program consists of the following:
e = get_next_event()
Here get_next_event is a magical function that returns the next thing
that has happened: generally input on some socket. handle_event does
the appropriate thing with e; in a chat system, you'll want to write a
copy of part of what was read to every output socket (or at least a
subset of them).
This necessarily means that all of your clients are connected to the
same process in some sense; you could do it in your current
architecture (which I understand is one process per player) by having
all the game processes talk to all the others, or having them connected
in some more complex way (such as a hypercube), but you'll probably
prefer a star topology.
If you write get_next_event yourself instead of using asyncore, it will
probably use the select function.
Hope this helps. I have example code I'd be happy to give you (a toy
chat server), but it's in C :)
<kragen at pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
The power didn't go out on 2000-01-01 either. :)
More information about the Python-list