1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
---
title: The WebSocket API (WebSockets)
slug: Web/API/WebSockets_API
translation_of: Web/API/WebSockets_API
---
<p>{{DefaultAPISidebar("Websockets API")}}</p>
<p>The <strong>WebSocket API</strong> is an advanced technology that makes it possible to open a two-way interactive communication session between the user's browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.</p>
<div class="blockIndicator note">
<p><strong>Note:</strong> While a WebSocket connection is functionally somewhat similar to standard Unix-style sockets, they are not related.</p>
</div>
<h2 id="Interfaces">Interfaces</h2>
<dl>
<dt><a href="/en-US/docs/Web/API/WebSocket"><code>WebSocket</code></a></dt>
<dd>The primary interface for connecting to a WebSocket server and then sending and receiving data on the connection.</dd>
<dt><code><a href="/en-US/docs/Web/API/CloseEvent">CloseEvent</a></code></dt>
<dd>The event sent by the WebSocket object when the connection closes.</dd>
<dt><a href="/en-US/docs/Web/API/MessageEvent"><code>MessageEvent</code></a></dt>
<dd>The event sent by the WebSocket object when a message is received from the server.</dd>
</dl>
<h2 id="Guides">Guides</h2>
<ul>
<li><a href="/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications">Writing WebSocket client applications</a></li>
<li><a href="/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers">Writing WebSocket servers</a></li>
<li><a href="/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_server">Writing a WebSocket server in C#</a></li>
<li><a href="/en-US/docs/Web/API/WebSockets_API/Writing_a_WebSocket_server_in_Java">Writing a WebSocket server in Java</a></li>
</ul>
<h2 id="Tools" name="Tools">Tools</h2>
<ul>
<li><a href="https://hacks.mozilla.org/2017/06/introducing-humblenet-a-cross-platform-networking-library-that-works-in-the-browser/">HumbleNet</a>: A cross-platform networking library that works in the browser. It consists of a C wrapper around WebSockets and WebRTC that abstracts away cross-browser differences, facilitating the creation of multi-user networking functionality for games and other apps.</li>
<li><a href="https://github.com/uWebSockets/uWebSockets">µWebSockets</a>: Highly scalable WebSocket server and client implementation for <a href="https://isocpp.org/">C++11</a> and <a href="https://nodejs.org">Node.js</a>.</li>
<li><a href="https://github.com/ClusterWS/ClusterWS">ClusterWS</a>: Lightweight, fast and powerful framework for building scalable WebSocket applications in <a href="https://nodejs.org">Node.js</a>.</li>
<li><a href="https://github.com/ClusterWS/cWS">CWS</a>: Fast C++ WebSocket implementation for Node.js (uWebSockets v0.14 fork)</li>
<li><a class="external" href="https://socket.io">Socket.IO</a>: A long polling/WebSocket based third party transfer protocol for <a href="https://nodejs.org">Node.js</a>.</li>
<li><a href="http://socketcluster.io/">SocketCluster</a>: A pub/sub WebSocket framework for <a href="https://nodejs.org">Node.js</a> with a focus on scalability.</li>
<li><a class="link-https" href="https://github.com/Worlize/WebSocket-Node">WebSocket-Node</a>: A WebSocket server API implementation for <a href="https://nodejs.org">Node.js</a>.</li>
<li><a href="http://www.totaljs.com">Total.js</a>: Web application framework for <a href="https://www.nodejs.org">Node.js</a> (Example: <a href="https://github.com/totaljs/examples/tree/master/websocket">WebSocket chat</a>)</li>
<li><a href="https://www.npmjs.com/package/faye-websocket">Faye</a>: A <a href="/en-US/docs/Web/API/WebSockets_API">WebSocket</a> (two-ways connections) and <a href="/en-US/docs/Web/API/EventSource/">EventSource</a> (one-way connections) for <a href="https://nodejs.org">Node.js</a> Server and Client.</li>
<li><a href="http://signalr.net/">SignalR</a>: SignalR will use WebSockets under the covers when it's available, and gracefully fallback to other techniques and technologies when it isn't, while your application code stays the same.</li>
<li><a href="https://caddyserver.com/docs/websocket">Caddy</a>: A web server capable of proxying arbitrary commands (stdin/stdout) as a websocket.</li>
<li><a href="https://github.com/websockets/ws">ws</a>: a popular WebSocket client & server library for <a href="https://nodejs.org/">Node.js</a>.</li>
<li><a href="https://github.com/bigstepinc/jsonrpc-bidirectional">jsonrpc-bidirectional</a>: Asynchronous RPC which, on a single connection, may have functions exported on the server and, and the same time, on the client (client may call server, server may also call client).</li>
<li><a href="https://github.com/ninenines/cowboy">cowboy</a>: Cowboy is a small, fast and modern HTTP server for Erlang/OTP with WebSocket support.</li>
</ul>
<h2 id="Related_Topics" name="Related_Topics">Related Topics</h2>
<ul>
<li><a href="/en-US/docs/Web/Guide/AJAX">AJAX</a></li>
<li><a href="/en-US/docs/Web/JavaScript">JavaScript</a></li>
</ul>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName("HTML WHATWG", "web-sockets.html", "WebSocket API")}}</td>
<td>{{Spec2("HTML WHATWG")}}</td>
<td></td>
</tr>
<tr>
<td><a href="https://www.w3.org/TR/websockets/">WebSockets</a></td>
<td><span class="spec-CR">Candidate Recommendation</span></td>
<td></td>
</tr>
<tr>
<td>{{RFC(6455, "The WebSocket Protocol")}}</td>
<td><span class="spec-RFC">IETF RFC</span></td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.WebSocket")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li><a class="external" href="http://tools.ietf.org/html/rfc6455">RFC 6455 — The WebSocket Protocol</a></li>
<li><a class="external" href="https://www.w3.org/TR/websockets/">WebSocket API Specification</a></li>
<li><a href="/en-US/docs/Server-sent_events">Server-Sent Events</a></li>
</ul>
|