There's a race condition, I think, in between writing the socket port
and running the socket server; it might be as simple as reordering the
writing and the socket opening, but strange things happened once when
I did that.
}
startSwank <- function(portFile) {
- acceptConnections(FALSE, portFile)
+ acceptConnections(4005, portFile)
}
acceptConnections <- function(port, portFile) {
+ if(portFile != FALSE) {
+ f <- file(portFile, open="w+")
+ cat(port, file=f)
+ close(f)
+ }
s <- socketConnection(host="localhost", server=TRUE, port=port, open="r+b")
on.exit(close(s))
serve(s)