Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created September 28, 2015 01:46
Show Gist options
  • Save MattSandy/90fc0b9dd45f69683588 to your computer and use it in GitHub Desktop.
Save MattSandy/90fc0b9dd45f69683588 to your computer and use it in GitHub Desktop.
Creates a websocket based JSON server
#Connect to this using websockets on port 9454
#Send in the format of {"data":[1,2,3]}
#The ppp returns the standard deviation of the sent array
library(jsonlite)
library(httpuv)
#server
app <- list(
onWSOpen = function(ws) {
ws$onMessage(function(binary, message) {
write(message, file = "log.txt",append = TRUE, sep = "\n")
message <- fromJSON(message)
ws$send(toJSON(sd(message$data)))
})
}
)
runServer("0.0.0.0", 9454, app, 250)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment