socket programming

Caltech News Server hsauro at cxx.calxxx.edu
Thu Mar 22 07:59:59 CET 2001


I think one possiblity is to send along with your string the number of
characters in your string. Then at the receving end, make two recv calls,
one to get the number of chars coming up and a second to retrieve all the
chars. I'm not sure but you may have to continue receiving until you've got
all characters.

Herbert Sauro

"Kevin X Lin" <klin at palsoccer.com> wrote in message
news:99bb0g0nce at enews3.newsguy.com...
> Hi there, I have the following problem with socket programming:
>
> I'm trying to setup a tcp client to talk to a tcp server sitting at a
> certain port. When I issue :
>
> mysocket.setblocking(1)
> mysocket.send('something')
> mysocket.recv(1024)
>
> I was expecting I can receive all the data sent by server. Unfortunately,
> this is not necessary the case. Sometimes I can't get all of data, worse,
> the application protocal doesn't define end tag of the data, which prevent
> me from doing a loop until I receive all data.
>
> But if I do this:
>
> mysocket.setblocking(1)
> mysocket.send('something')
> sleep(0.1)
> mysocket.recv(1024)
>
> I can get all data, yet I believe this is not a good solution which might
> casusing other problems in the future.
>
> Any suggestion?
>
> Thanks.
>
> Kevin
>
>
>
>





More information about the Python-list mailing list