[R] limit on read.socket?

Thomas Lumley tlumley at u.washington.edu
Mon Sep 6 23:08:00 CEST 2010


On Sat, 4 Sep 2010, rajeshj at cse.iitm.ac.in wrote:

>
> Hi,
>
> I have the following piece of code,
>
> repeat{
>
> ss<-read.socket(sockfd);
> if(ss=="") break
> output<-paste(output,ss)
> }
>
> but somehow, output is not receiving all the data that is coming through the socket.My suspicion is on the if statement. what happens if a white space occurs in between the string arriving over the socket?

That's not the problem.  The problem occurs when R reads faster than the data are provided -- R will read and there will not be any new data available, so ss will be the empty string and the program will end.

In general you can't rely on the sender transmitting data fast enough to keep ahead of R.  The example in make.socket() is reading a very small amount of data, so it worked reasonably well back in the days when the finger daemon was more widely active.   You need some more precise way of knowing when the data stream is over.  This could be some sort of 'end of transmission' marker or a count of the number of bytes or lines to be expected.

    -thomas

Thomas Lumley
Professor of Biostatistics
University of Washington, Seattle



More information about the R-help mailing list