WebSockets
suggest changeIntroduction
WebSocket is a protocol, which enables two-way communication between a client and server.
The goal of WebSocket is to provide a mechanism for browser-based applications that need two-way communication with servers that does not rely on opening multiple HTTP connections. (RFC 6455)
The opening handshake uses HTTP, and then the connection is upgraded. It does not stay on HTTP. The URL uses the ws: or wss: scheme.
Syntax
- new WebSocket(url)
- ws.binaryType /* delivery type of received message: “arraybuffer” or “blob” */
- ws.close()
- ws.send(data)
- ws.onmessage = function(message) { /* … */ }
- ws.onopen = function() { /* … */ }
- ws.onerror = function() { /* … */ }
- ws.onclose = function() { /* … */ }
Parameters
| Parameter | Details |
|---|---|
| url | The server url supporting this web socket connection. |
| data | The content to send to the host. |
| message | The message received from the host. |
Establish a web socket connection
Making a secure web socket connection
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents