'\" t .\" Title: nn_ws .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.20 .\" Date: 2024-02-21 .\" Manual: nanomsg 1.2.1 .\" Source: \ \& .\" Language: English .\" .TH "NN_WS" "7" "2024-02-21" "\ \&" "nanomsg 1.2.1" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" nn_ws \- WebSocket transport mechanism .SH "SYNOPSIS" .sp \fB#include \fP .sp \fB#include \fP .SH "DESCRIPTION" .sp The WebSocket transport uses the framing protocol specified in RFC 6455 to transport messages. The initial handshake is done using HTTP headers, with the \f(CRSec\-Websocket\-Protocol\fP header set to the SP protocol used by the server. For example, a REQ client will send \f(CRrep.sp.nanomsg.org\fP. .sp Each SP message is transported in a single WebSocket frame, with no additional data or headers applied. By default this library sends and expects to receive binary frames. .sp When calling either \f(CRnn_bind()\fP or \f(CRnn_connect()\fP, omitting the port defaults to the RFC 6455 default port 80 for HTTP. For example, \f(CRws://127.0.0.1\fP is equivalent to \f(CRws://127.0.0.1:80\fP .sp WebSocket over TLS is not supported by this library, at this time. .SS "URI limitations" .sp When calling \f(CRnn_connect()\fP, the URI may also optionally include the path to a resource and/or query parameters. .sp .B Example 1. Path and query parameters .br .RS 4 .sp .if n .RS 4 .nf .fam C s1 = nn_socket (AF_SP, NN_PAIR); nn_connect (s1, "ws://example.com/path?query=value"); .fam .fi .if n .RE .RE .sp This implementation includes the full path and any query parameters in the HTTP handshake when establishing connections with \f(CRnn_connect()\fP. This information is not available via the nanomsg API afterwards, however. .sp Likewise, this implementation does not examine or use either any path or query parameters that may be supplied to \f(CRnn_bind()\fP, as it only binds to the TCP port. This implementation acts as a limited HTTP server that offers SP over WebSocket at all URIs for the given TCP address. .sp Applications, however, should not depend on this behavior; intervening infrastructure may proxy, filter or route based on URI, and other implementations of the SP over WebSocket protocol may offer other HTTP services at the same TCP port, utilizing the path, query parameters, or both to determine the service to be used. .SS "Socket Options" .sp NN_WS_MSG_TYPE .RS 4 This option may be set to NN_WS_MSG_TYPE_TEXT or NN_WS_MSG_TYPE_BINARY. The value of this determines whether data messages are sent as WebSocket text frames, or binary frames, per RFC 6455. Text frames should contain only valid UTF\-8 text in their payload, or they will be rejected. Binary frames may contain any data. Not all WebSocket implementations support binary frames. The default is to send binary frames. .sp This option may also be specified as control data when when sending a message with \f(CRnn_sendmsg()\fP. .RE .sp TODO: NN_TCP_NODELAY .RS 4 This option, when set to 1, disables Nagle\(cqs algorithm. It also disables delaying of TCP acknowledgments. Using this option improves latency at the expense of throughput. Type of this option is int. Default value is 0. .RE .SH "EXAMPLE" .sp .if n .RS 4 .nf .fam C nn_bind (s1, "ws://*:5555"); nn_connect (s2, "ws://myserver:5555"); .fam .fi .if n .RE .SH "SEE ALSO" .sp nn_tcp(7) nn_inproc(7) nn_ipc(7) nn_bind(3) nn_connect(3) nanomsg(7) .SH "AUTHORS" .sp \c .MTO "sustrik\(at250bpm.com" "Martin Sustrik" \c .MTO "jack\(atwirebirdlabs.com" "Jack R. Dunaway" .MTO "garrett\(atdamore.org" "Garrett D\(cqAmore" ""