Two Pythons talking to each other?

Phil Mayes nospam at bitbucket.com
Thu Jul 8 03:02:56 EDT 1999


Hans Nowak wrote in message <199907080529.HAA19502 at axil.hvision.nl>...

>On 7 Jul 99, Charles G Waldman wrote:
>> There's no reason, just because the two programs are running on the same
>> machine, that they can't talk to each other using network protocols
>>[snip]
>I just tested this, and it works. But now I have another problem &
>question (which may be stupid, but I know hardly anything about
>networking and sockets). My programs send commands to each other in
>IRC style (like "/say this") or just plain text (chat). For receiving
>these strings, I use a non-blocking socket connection which polls the
>server every 0.x seconds (the period may vary). However, when the
>strings are sent too fast, which is the case with the 127.0.0.1
>address, and sometimes with regular connections too, the other side
>will pick two strings up as one string.
>
>So my question is, how does one generally deal with this? Should I
>attach a newline (\n) (or maybe another separator character) after
>every string? Or are there other ways to guarantee that two commands
>will arrive at the other side as two strings?


I think your best bet is to look at asyncore.py and asynchat.py which
are in the std lib as of 1.5.2.  I've just prototyped a client/server
using these, with both running on one machine.  Oh yes, take a look at
the samples that came with the original async lib:
http://www.nightmare.com/software.html (Thanks, Sam)
--
Phil Mayes    pmayes AT olivebr DOT com









More information about the Python-list mailing list