Sockets
Peter Hansen
peter at engcorp.com
Wed Oct 10 22:47:47 EDT 2001
Hugo Martires wrote:
>
> My server need to send 2 strings separeted:
> s1= 'xxx'
> s2= 'yyy'
>
> My client must received like this:
> rec1= 'xxx'
> rec2= 'yyy'
>
> The problem is that the Client received s1 and s2 in one only string.
>
> How can i received in 2 separeted variables ?
I note the other answers, and still feel the need to point out two
things.
1. When asking questions of this sort, it is *always* advisable
to post sample code showing what you are trying to do.
If you don't, the answers are just guesses (maybe educated ones,
but still guesses).
2. Assuming you are opening a socket between the two programs,
my (educated :-) guess is that you are doing a pair of socket.send()
calls with the two strings, and expecting these two be
received *separately* with two recv() calls on the other end.
If this is so, you misunderstand how sockets and TCP/IP and
such work. Nowhere in the documentation will you find any
guarantee that the data from two consecutive send() calls
matches up with the two recv() calls. They might be lumped
together so that you get 'xxxyyy' after the first recv().
You might have to use four recv() calls and get 'x', 'x',
'xxy' and finally 'yy'. No guarantees. Don't ever assume
you have all the data just because recv() returns.
And that's the reason behind John's suggestion of disabling
the Nagel algorithm, since it *might* appear to solve the
problem. Don't be fooled: it's a very fragile, hackish
way of "fixing" the problem, and not suitable for "real"
programs in most cases. (Standard anti-flame disclaimers
apply...)
--
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com
More information about the Python-list
mailing list