[R] How to detect a closed socket when writing?

From: rsubscriber <rsubscriber_at_slcmsr.net>
Date: Wed 08 Jun 2005 - 00:46:27 EST


Hi,

is it possible to detect, whether the other side has closed a socket connection when writing on this socket?

When i am trying this with two R instances R 1 and R 2, i expected that the last writeLines would give an error, but the call seems to be successfull:

R 1>  s<-socketConnection(port=2000, server=T, blocking=T, open="r+b")
R 2>  s<-socketConnection(port=2000, server=F, blocking=T, open="r+b")
R 1>  CloseAllConnections()
R 2>  writeLines("test", s)  # seems to succeed
R 2>  isIncomplete(s)        # returns FALSE

Only if i write a very long strings instead of "test", the writeLines call blocks and gives a warning after timing out. The same happens with writeBin.

I tried this with R-2.1.0 and R-2.0.1 under Ubuntu hoary.

This is a problem for me, because i am writing a statistics server in R, which communicates over a socket connection with a Java web server. The other side has timeouts and may close the connection before the result of a long-standing calculation has been sent. In this case, the R server should detect, that the connection was closed and try to reconnect. But this is not possible, if the write seems successfull.

Is this a bug, which will be solved in future releases, or a feature?

Christian



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jun 08 00:54:25 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:27 EST