Closed jbShi1017 closed 5 months ago
Are you trying to connect from localhost, or from another computer? If you are able to connect from localhost but not another computer, then I think it is likely that your Linux machine has some firewall rules that are blocking the connection.
unadble to connect from localhost
Oh, I think I see the problem. It's the while(TRUE){}
loop. This blocks the R process and won't get the httpuv server a chance to respond to anything. I am surprised to hear that this same code works on Windows.
You should get rid of the while
loop and use runServer()
instead of startServer()
. The runServer()
function will start the server and then drive the event loop which httpuv uses to respond to requests.
Or you could call startServer()
and then call httpuv::service(0)
. That is essentially what runServer()
does.
Oh,thank you!
`library(httpuv)
s <- startServer(host = "0.0.0.0", port = 8080, app = list( call = function(req) { body <- paste0("Time: ", Sys.time(), "
Path requested: ", req$PATH_INFO) list( status = 200L, headers = list('Content-Type' = 'text/html'), body = body ) } ) )
while (TRUE){
}`
I used this code to create a service on Linux, but there was no response when accessing it, and there was no problem with Windows httpuv version: 1.6.15 R version: 4.3.3