|
Posted by jm on March 7, 2008, 6:05 pm
Please log in for more thread options Jim Gibson 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.
>>
>> I just want it to be blocked when no byte is available.
>>
>> When I do not use a size of 512 or 4096, but a size of 1, everything
>> works fine, but I am wondering if it will not be too much slow.
>>
>> my $buffer = '';
>> while ( not $buffer =~ /\n\n/ )
>> {
>> my $packet;
>> sysread $sock, $packet, 4096 ;
>> $buffer .= $packet ;
>> }
>
> How do you know the problem is not with your server? We can't tell,
> since you have not shown us your code. You should 1) capture the return
> value of sysread and check it for a) the number of bytes read, b) a 0
> if the socket has been closed, or c) undef if an error has occurred,
> and 2) print the return value and the bytes read, if any.
When debugging the code, I had replaced sysread, by recv and read methods.
I moved back to the sysread, and it looks like working fine.
However, I am not sure documentation clearly explain why $sock->send for
sending, and why sysread for reading...
thanks.
|