|
Posted by jm on March 6, 2008, 6:57 pm
Please log in for more thread options Ben Morrow a écrit :
>> I have written some perl client program and javascript server program.
>>
>> Communication seams working in both direction, but the perl client
>> cannot read final data.
>>
>> Perl use socket in blocking mode (default).
>> I open the connection with localhost, port number, and tcp.
>>
>> When I read packets with a size of 512 or 4096, everything works fine
>> till the last packet. As the last packet is smaller than 4096, perl stay
>> blocked waiting for a complete packet.
> When you say 'last packet', do you mean 'last packet before the
> connection is closed' or 'last packet in this request'?
I mean the server send several lines of text, then an empty line.
Then the server wait for the client.
All theses lines of text are assembled by network stacks in buffers of
4096 bytes, but last characters wont.
> If you mean the
> former, then Perl will return an incomplete packet even in blocking
> mode.
> If the latter, then you need to set the socket to non-blocking
> mode, and be prepared to handle short reads all the way through. You
> will also need to use IO::Select to wait for data after you get a short
> read.
>
> Ben
>
I was believing blocking mode better than non blocking!
|