create_server: Create a websocket server.

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/websockets.R


Create a websocket server and bind it to a port.


create_server(port = 7681L, webpage = static_file_service(paste(system.file(package = "websockets"), "basic.html", sep = "//")), is.binary = FALSE)
createContext(port = 7681L, webpage = static_file_service(paste(system.file(package = "websockets"), "basic.html", sep = "//")), server = TRUE, is.binary = FALSE)



The service port number.


Optionally, specifiy a function to service HTTP requests. This value may be NULL.


Set FALSE if the environment will represent a client connection (used internally by the websocket function.


The websocket connection binary transport flag.


The websockets package supports an arbitrary number of servers, each listening on a distinct TCP port number. An environment is associated with each running server. Server events must be serviced with the service function.

The webpage callback must be a function of two arguments, socket and header. The socket argument indicates the low-level socket descriptor of the client. The header argument contains a parsed HTTP request header. When invoked, the function may examine the request and respond using the http_response and http_vars functions.


An environment is returned. The R/Websocket service will search the environment for callback functions named: closed, established, and receive. The established and closed functions must take a single argument (a websocket). The receive function must take three arguments: DATA, WS, and '...', holding the message data, websocket client, and possible ancillary information received. The callback functions are optional. When a websocket event occurs, the corresponding function will be evaluated if it exists. The DATA parameter holds a RAW vector with incoming data from broadcast or receive events, and may be of length zero for other events. The WS parameter is the client web socket corresponding to the event.

See the set_callback function for more information.


B. W. Lewis <[email protected]>

See Also

service, websocket_broadcast websocket_write set_callback http_response http_vars


# See the detailed example in help('websockets').

rstudio/R-Websockets documentation built on May 25, 2017, 8 p.m.