On Dec 1, 2003, at 2:02 PM, Kipp, James wrote:

Hi
I have simple client/server socket scripts that that send some data from the
server to the client. It works fine, except the client can't seem to read
more than 2920 bytes from the server using sysread(). So the data I am
sending over gets cut off. Here is the relevant code:


---
connect(SOCK, $remote) or die "can't connect: $!\n";

$bytes = sysread(SOCK,$buf,4096);
print "read $bytes bytes from server.\n server said: $buf";

-----
It works fine if I use:
while ( <SOCK> ) { print }


Any ideas? Thank You !

Yes. Calling sysread() gets you what's ready to be read UP TO the amount of data you specify. The rest probably just wasn't available yet. There could be a lot of reasons for this: network lag, operating system buffers, etc.


You're second example is line oriented. It returns when it has collected a whole line. That's a big difference.

If you can get by with the line oriented reads and writes, by all means use them and save yourself a lot of pain. That's rare in networking though, in my experience.

If you really do need sysread(), you'll need to check it with select() to see when data is available and buffer your reads until you know you have an entire message.

Hope that helps.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to