-
-
Save sandys/2c5a70b95694f675fda4 to your computer and use it in GitHub Desktop.
Creates a websocket based JSON server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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