Two Pythons talking to each other?

Hans Nowak ivnowa at hvision.nl
Thu Jul 8 01:30:40 EDT 1999


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
> (TCP/IP, sockets, etc).  You can use the "loopback" address of 127.0.0.1
> to make all connections.  You really don't want to develop and test using
> a completely different communications scheme (e.g. pipes, files) then
> re-implement everything for the networked version, and debug it all over
> again.  Client and server can both run on the same box.

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?

TIA,

--Hans Nowak (ivnowa at hvision.nl)
Homepage: http://fly.to/zephyrfalcon




More information about the Python-list mailing list