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 }
That's the nature of stream sockets. There are no defined message boundaries, so you have to keep reading until you've read all the data you need, based upon the protocol being used by the client and server. sysread() will return as soon as some data is available. It only blocks if no data at all is available. The second example essentially blocks until a line terminator has been read. As long as the remote side sends messages as lines, that will work fine. Of course, you also have to deal with timeouts in this kind of application (what if the network between the hosts goes down before the entire message has been read? The reader will block forever). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]