The WebSocket protocol enables two-way communication between client and server even when a firewall and/or NAT are present between them. This means, once a WebSocket connection is established, request (and response) primitives can be exchanged in both directions, from the client to the server and vice versa. However, AEs may be capable of handling Notification request primitives only, or no request primitives at all.
WebSocket binding applied by oneM2M entities/nodes shall be fully compliant with IETF RFC 6455 [1]. After establishment of a WebSocket connection between two nodes, at the transmitter side each individual request and response primitive is mapped into one or several WebSocket frames.
A WebSocket connection is opened by the client side as specified in section 4 of IETF RFC 6455 [1] with sending of a client handshake. The server responds with a server handshake.
The client handshake consists of an HTTP upgrade request, along with a list of required and optional header fields.
The handshake shall be a valid HTTP request as specified by IETF RFC 7230 [3]. The server handshake consists of a HTTP status-line and a list of header fields.
The applicable format of the request-line, status-line and the applicable header fields are specified in the following sub-clauses.
HTTP headers fields have case-insensitive field names.
CSEs capable to support WebSocket shall indicate the schemes ws and/or wss together with the applicable host name and port numbers in the pointOfAccess attribute of their
By default, the WebSocket Protocol [1] uses port 80 for regular WebSocket connections and port 443 for WebSocket connections over Transport Layer Security (TLS). If a WebSocket URI does not include an explicit port number, the default port number shall apply. Possible example representations of the pointOfAccess attribute
ws://ws-server.example.com:80
ws://ws-server.example.com
wss://10.251.232.119:443
NOTE: ADN-AEs and ASN-CSEs do not need to support WebSocket servers and therefore do not require a WebSocket URI in the pointOfAccess attribute (see figure 5.2.1).
NOTE: ADN-AEs and ASN-CSEs do not need to support WebSocket servers and therefore do not require a WebSocket URI in the pointOfAccess attribute (see Figure 5.2‑1).
The request-line of a client handshake shall begin with the method token "GET", followed by the request target "/" and the HTTP version set to "HTTP/1.1" as follows:
GET / HTTP/1.1If the client is configured to use a proxy when using the WebSocket Protocol, a connection to the proxy server shall be established prior to sending the above client handshake. This is described in clause 6.6.
The Host header shall be present in each client handshake.
The Host header indicates the FQDN or IP address of the Receiver CSE of the next hop. If the originator of the client handshake is an oneM2M field entity, the host header represents the registrar CSE of the originator.
When no proxy is used, the Host header shall be set as one of the pointOfAccess attribute values associated with the Receiver. Selection of the appropriate Receiver is described in oneM2M TS-0004 [5].
If the client is configured to use a proxy when using the WebSocket Protocol, then the client should connect to that proxy and ask it to open a TCP connection to the host and port rather than to the next hop CSE.
The Upgrade header shall be present in each client handshake message with value WebSocket as follows:
Upgrade: WebSocketThe Connection header shall be present in each client handshake message with value Upgrade as follows:
Connection: UpgradeThe Sec-WebSocket-Key header shall be present in each client handshake message. The header field includes a base64-encoded representation of a random 16 bytes pattern, for example:
Sec-WebSocket-Key: ud63env87LQLd4uIV20/oQ==The Sec-WebSocket-Version header shall be present in each client handshake message with value 13 as follows:
Sec-WebSocket-Version: 13The Sec-WebSocket-Protocol header shall be present in a client handshake message. It enables the client to indicate its supported application subprotocols on the server and be sure that the server agreed to support that subprotocol. It is used by the client to indicate the oneM2M Service Layer Protocol version and supported serialization formats to the server.
The value of the Sec-WebSocket-Protocol header shall be one or more of the registered names defined in clause 6.2.2.9. It shall also be allowed to include multiple Sec-WebSocket-Protocol headers with a value that includes one registered name each as defined in IETF RFC 6455 [1], for example:
Sec-WebSocket-Protocol: oneM2M.json, oneM2M.xmland
Sec-WebSocket-Protocol: oneM2M.xml
Sec-WebSocket-Protocol: oneM2M.jsonare equivalent headers, expressing that the WebSocket client supports both application subprotocols, oneM2M.json and oneM2M.xml. The order of names indicated in the Sec-WebSocket-Protocol header specifies the client's preference.
The Sec-WebSocket-Extensions header may be used to negotiate the use of per-message compression as specified in IETF RFC 7692 [6].
If the client handshake includes the header, e.g.
Sec-WebSocket-Extensions: permessage-deflateit indicates to the server the client's preference to apply the compression mechanism defined in IETF RFC 7692 [6]. The header may include additional parameters as specified in IETF RFC 7692 [6].
When the server accepts use of message compression it responds with a Sec-WebSocket-Extensions header in the server handshake message as specified in clause 6.2.3.6, and in this case compression is applied in both transmission directions. If the server handshake message does not include a Sec-WebSocket-Extensions header, compression shall not be applied.
The Sec-WebSocket-Protocol header in the opening handshake is used to negotiate the application protocol layered on top of WebSocket. The application protocol addressed in this specification is the Release-2 version ofe present document is the oneM2M Service Layer protocol.
The oneM2M Service Layer Pprotocol consists of the exchange of serialized representations of request and response primitives as defined in oneM2M TS-0001 [2] and oneM2M TS-0004 [5]. This version of the specificationpresent document allows use of the serialization formats listed in table 6.2.2.9‑1. Both, protocol version andEach serialization format areis associated with a specific subprotocol name.
Table 6.2.2.9‑1 lists the, for each serialization formats, associatedthe subprotocols names and opcode setting of the WebSocket Frame protocol applicable for the present version of this specification that shall be used in the opening handshake and the opcode that shall be used in the WebSocket Frame protocol.
Table 6.2.2.9‑1: Applicable Subprotocol names
Serialization Format
|
Subprotocol Name
|
WS opcode
|
Notes
|
|---|---|---|---|
JSON
|
oneM2M.json
|
x1 ("text frame")
|
See clause 8.4 in oneM2M TS-0004 [5]
|
XML
|
oneM2M.xml
|
x1 ("text frame")
|
See clause 8.3 in oneM2M TS-0004 [5]
|
CBOR
|
oneM2M.cbor
|
x2 ("binary frame")
|
See clause 8.5 in oneM2M TS-0004 [5]
|
The status-line of a server handshake shall begin with the HTTP version set to "HTTP/1.1", followed by the status code and reason phrase as defined in IETF RFC 6455 [1]. When the WebSocket connection is established successfully, the status-line may look as follows:
HTTP/1.1 101 Switching ProtocolsFor the unsuccessful connection establishment, any appropriate HTTP error status code shall be returned with optional addition of a corresponding reason phrase.
The Upgrade header shall be present in each server handshake message with value WebSocket as follows:
Upgrade: WebSocketThe Connection header shall be present in each server handshake message with value Upgrade as follows:
Connection: UpgradeThe Sec-WebSocket-Accept header shall be present in each server handshake message. The header field shall be constructed from the Sec-WebSocket-Key value and the GUID as specified in section 4.2.2 of IETF RFC 6455 [1]. It may look e.g. as follows:
Sec-WebSocket-Accept: FuSSKANnI7C/6/FrPMt70mfBY8E=The Sec-WebSocket-Protocol header shall be present in a server handshake message. It indicates to the client that the server accepts (one of) the subprotocol(s) indicated by the client.
The server compliant with this specificatione present document shall select one of the subprotocol names indicated in the Sec-WebSocket-Protocol header of the client handshake message and set the value of the Sec-WebSocket-Protocol header of the server handshake message accordingly.
If the optional Sec-WebSocket-Extensions header with value "permessage-deflate" was included in the client handshake message, the Sec-WebSocket-Extensions header with same value shall also be included into the server handshake message, if the server accepts usage of message compression, and apply message compression in the transmit direction and message decompression in the receive direction as defined in IETF RFC 7692 [6].
If the server does not accept message compression, it shall not include the Sec-WebSocket-Extensions header.
Compliant with section 7 of IETF RFC 6455 [1] a WebSocket connection shall be closed by sending a Connection Close Frame (opcode x8). Both, client and server may initiate a closing handshake of an existing WebSocket connection at any time.
WebSocket connections should be kept open for as long as possible considering any given constraints due to communication policies and power saving requirements. Unless communication policies enforce the closing of network access, it is left to implementation to decide when exactly the closing of a WebSocket shall be triggered.
A oneM2M entity (AE or CSE) not yet registered to its registrar CSE needs to be preconfigured with various parameters as specified in oneM2M TS-0001 [2] and oneM2M TS-0003 [4] in order to be able to send the registration request primitive (i.e. create
After the Registration procedure has been successfully completed, the WebSocket Server (e.g. Registrar CSE for WebSocket Client) shall enable routing of any incoming oneM2M primitives to this registree.
Before the Registration procedure is successfully completed, any incoming oneM2M primitives to the WebClient shall be rejected by the Receiver (e.g. registrar CSE).
Closing of the WebSocket connection after registration does not impact the registration status of an AE or CSE to its registrar, unless an explicit de-registration procedure is performed by deletion of the respective
Registered entities (AE and CSE) are allowed to send and receive non-registration request primitives. A WebSocket connection should support any of the transfer modes defined in clause 8.2 of oneM2M TS-0001 [2], i.e. blocking requests, and non-blocking requests for both synchronous and asynchronous cases.
When sending blocking requests, the WebSocket connection shall not be closed before the response is received, or before any configured timeout period has expired.
When sending non-blocking requests, the WebSocket connection shall not be closed before the acknowledgment response is received, or before any configured timeout period has expired. If the entities' communication policies and power saving requirements allow, the connection should be kept open at least until an ongoing procedure has fully completed, i.e. requesting of the result in synchronous mode or completion of Notify procedure in asynchronous mode.
If no WebSocket connection with a client exists when a Notify request primitive for this client becomes available at the server side, it should be stored and sent when the WebSocket connection is opened again by the client.
The connection to a proxy shall be requested by sending a request-line with the method token "CONNECT", followed by the request target host and port of the WebSocket server and the HTTP version set to "HTTP/1.1" for example as follows:
CONNECT WSserver.example.com:80 HTTP/1.1