Socket and cycle problem
Jean-Paul Calderone
exarkun at divmod.com
Mon May 12 13:16:29 EDT 2008
On Mon, 12 May 2008 09:19:48 -0700 (PDT), petr.poupa at gmail.com wrote:
>
> [snip]
>>
>> >Where is the mistake? I dont know.
>>
>> You cannot reconnect a socket. You need to create a new one for each
>> connection. It's also almost certainly the case that the way you are
>> receiving data is incorrect. There is no guarantee that you will get
>> 2048 bytes from socket.recv(2048). It isn't even guaranteed that all
>> the bytes written to the socket by the peer will be returned by such
>> a call. Instead, you need a framing protocol to determine when all
>> data has been received. For example, you might length prefix the
>> data, or you might insert a delimiter (or a terminator) at the end. Or
>> if there is exactly one message to receive, then you should just read
>> until the recv call returns '', indicating EOF.
>>
>> Jean-Paul
>
>ok thanks, but I am true greenhorn, so you think that the best way is
>write new script?
>Could you send me code if it isnt long, becase I have no idea and
>unfortunately time as well.
>
I'm not sure what you want to happen, so I can't write it for you. I
suggest you start with Twisted instead of the socket module, though,
as Twisted provides a higher-level interface to network programming.
You can find some introductory documentation about writing clients here:
http://twistedmatrix.com/projects/core/documentation/howto/clients.html
Jean-Paul
More information about the Python-list
mailing list