create_server: Create a websocket server.

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

View source: R/websockets.R

Description

Create a websocket server and bind it to a port.

Usage

1
2
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)

Arguments

port

The service port number.

webpage

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

server

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

is.binary

The websocket connection binary transport flag.

Details

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.

Value

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.

Author(s)

B. W. Lewis <blewis@illposed.net>

See Also

service, websocket_broadcast websocket_write set_callback http_response http_vars

Examples

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

rstudio/R-Websockets documentation built on May 28, 2019, 4:33 a.m.