Description Usage Arguments Details Value Author(s) See Also Examples
Create a websocket server and bind it to a port.
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)
|
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 |
is.binary |
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 <blewis@illposed.net>
service
,
websocket_broadcast
websocket_write
set_callback
http_response
http_vars
1 | # See the detailed example in help('websockets').
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.