limit on read.socket?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

limit on read.socket?

rajeshj@cse.iitm.ac.in

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?
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: limit on read.socket?

Thomas Lumley
On Sat, 4 Sep 2010, [hidden email] 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.