library(httpuv)
.lastMessage <- NULL
app <- list(
call = function(req) {
wsUrl = paste(sep='',
'"',
"ws://",
ifelse(is.null(req$HTTP_HOST), req$SERVER_NAME, req$HTTP_HOST),
'"')
list(
status = 200L,
headers = list(
'Content-Type' = 'text/html'
),
body = paste(
sep = "\r\n",
"",
"",
"
",
'',
"",
"",
"",
'Send Message
',
'',
"",
""
)
)
},
onWSOpen = function(ws) {
ws$onMessage(function(binary, message) {
.lastMessage <<- message
ws$send(message)
})
}
)
server <- startDaemonizedServer("0.0.0.0", 9454, app)
# check the value of .lastMessage after echoing to check it is being updated
# call this after done
#stopDaemonizedServer(server)