MattSandy
9/28/2015 - 1:46 AM

Creates a websocket based JSON server

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)