Description Usage Arguments Details Value Note Author(s) See Also Examples
Create a websocket client connection.
1 |
url |
The websocket url to connect to. |
port |
The service port number. |
subprotocol |
A websocket subprotocol id. |
version |
A websocket protocol version. |
Create a context for a websocket client connection. All the functions
available to a websocket server context, including callbacks for handling
events for the connection, may be defined just as with a server
context created with create_server
.
The websocket_write
function can also be used to write data
through the websocket client socket to the service.
An environment is returned. The 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 HEADER,
holding the message data, websocket client, and possible
ancillary header 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.
This package supports websocket protocol version numbers 0 and 8. Version 0 is the original draft websocket protocol specification. If your websocket service requires a different protocol version, it will probably also work since the newer protocols do not vary significantly in messaging details.
Once the websocket standard is set, this package will be updated to fully reflect the standardized version.
B. W. Lewis <blewis@illposed.net>
service
,
websocket_write
set_callback
1 2 3 4 5 6 7 8 9 | # Connect to the public websocket echo service
## Not run:
client = websocket("ws://echo.websocket.org")
set_callback("receive", function(DATA, WS, HEADER) cat(rawToChar(DATA),"\n"), client)
websocket_write("Testing, testing", client)
service(client)
websocket_close(client)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.