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

rsubscriber rsubscriber at slcmsr.net
Tue Jun 7 16:46:27 CEST 2005


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




More information about the R-help mailing list