WebSocket
Object provides a set of APIs for creating and managing WebSocket connections, and for sending and receiving data over that connection.
The WebSocket constructor method accepts a required parameter and an optional parameter:
WebSocket WebSocket (in domstring URL, in optional domstring protocols); WebSocket WebSocket (in domstring url,in Optional domstring[] protocols);
Parameters
-
url
-
Represents the URL to connect to. This URL should be in response to the WebSocket address.
-
protocols
options available
-
can be a single protocol name string or an array that contains multiple protocol moniker strings. These strings are used to represent sub-protocols, which allows a server to implement multiple WebSocket sub-protocols (for example, you might want to handle different types of interactions by developing different protocols). If this parameter is not set, it is set to an empty string by default.
The constructor method may throw the following exception:
-
SECURITY_ERR
-
The port you are trying to connect to is masked.
Method Overview
-
void Close (in optional unsigned long code, in optional domstring reason);
void Send (in domstring data);
Properties
Reference article link: https://developer.mozilla.org/zh-CN/docs/Web/API/WebSocket
Study notes of WebSocket learning cocoscreator Contact