Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 997319 of WebSockets

  • Revision slug: Web/API/WebSockets_API
  • Revision title: WebSockets
  • Revision id: 997319
  • Created:
  • Creator: hasan3ysf
  • Is current revision? No
  • Comment

Revision Content

{{DefaultAPISidebar("Websockets API")}}

WebSockets is an advanced technology that makes it possible to open an 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.

Interfaces

WebSocket
The primary interface for connecting to a WebSocket server and then sending and receiving data on the connection.
CloseEvent
The event sent by the WebSocket object when the connection closes.
MessageEvent
The event sent by the WebSocket object when a message is received from the server.

Tools

 

See also

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Version -76 support {{obsolete_inline}} 6 {{CompatGeckoDesktop("2.0")}} {{CompatNo}} 11.00 (disabled) 5.0.1
Protocol version 7 support {{obsolete_inline}} {{CompatNo}} {{CompatGeckoDesktop("6.0")}}
{{property_prefix("Moz")}}
{{CompatNo}} {{CompatNo}} {{CompatNo}}
Protocol version 10 support {{obsolete_inline}} 14 {{CompatGeckoDesktop("7.0")}}
{{property_prefix("Moz")}}
HTML5 Labs {{CompatUnknown}} {{CompatUnknown}}
Standard - RFC 6455 Support 16 {{CompatGeckoDesktop("11.0")}} 10 12.10 6.0
Usable in Workers {{CompatVersionUnknown}} {{CompatGeckoDesktop("37.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Version -76 support {{obsolete_inline}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Protocol version 7 support {{obsolete_inline}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Protocol version 8 support (IETF draft 10) {{obsolete_inline}} {{CompatUnknown}} {{CompatGeckoMobile("7.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Standard - RFC 6455 Support 4.4 {{CompatGeckoDesktop("11.0")}} {{CompatUnknown}} 12.10 6.0
Usable in Workers {{CompatVersionUnknown}} {{CompatGeckoMobile("37.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

Gecko notes

WebSockets support in Firefox is continuing to track the evolving WebSocket specification. Firefox 6 implements version 7 of the underlying protocol, while Firefox 7 implements version 8 (as specified by IETF draft 10). Firefox mobile received WebSocket support in Firefox mobile 7.0.

Gecko 6.0

Prior to Gecko 6.0 {{geckoRelease("6.0")}}, there was, incorrectly, a WebSocket object that some sites were thinking implied that WebSocket services were not prefixed; this object has been renamed to MozWebSocket.

Gecko 7.0

Starting in Gecko 7.0 {{geckoRelease("7.0")}}, the network.websocket.max-connections preference is used to determine the maximum number of WebSocket connections that can be open at a time. The default value is 200.

Gecko 8.0

Starting in Gecko 8.0 {{geckoRelease("8.0")}}, the deflate-stream extension to the WebSocket protocol has been disabled, since it's been deprecated from the specification drafts. This resolves incompatibilities with some sites.

Gecko 11.0

Prior to Gecko 11.0, both incoming and outgoing messages were limited to 16 MB in size. They may now be up to 2 GB in size. Note, however, that memory limitations (especially on mobile devices) make that a theoretical maximum, not a practical one. In reality, transfers of that size will fail on devices that don't have enough memory.

Additionally, ArrayBuffer send and receive support for binary data has been implemented.

Starting in Gecko 11.0, the WebSocket API is no longer prefixed.

Revision Source

<p>{{DefaultAPISidebar("Websockets API")}}</p>

<p><strong>WebSockets</strong> is an advanced technology that makes it possible to open an 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>

<h2 id="Interfaces">Interfaces</h2>

<dl>
 <dt><a href="/en-US/docs/Web/API/WebSocket" title="en/WebSockets/WebSockets reference/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" title="en/WebSockets/WebSockets reference/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" title="en/WebSockets/WebSockets reference/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 class="Tools" id="Tools" name="Tools">Tools</h2>

<p>&nbsp;</p>

<ul>
 <li><a class="external" href="https://socket.io" title="https://socket.io/">Socket.IO</a>: A powerful cross-platform WebSocket API for <a class="external" href="https://nodejs.org" title="https://nodejs.org/">Node.js</a>.</li>
 <li><a class="link-https" href="https://github.com/Worlize/WebSocket-Node" title="https://github.com/Worlize/WebSocket-Node">WebSocket-Node</a>: A WebSocket server API implementation for <a class="external" href="https://nodejs.org" title="https://nodejs.org/">Node.js</a>.</li>
 <li><a href="https://www.totaljs.com">Total.js</a>: Web application framework for <a href="https://www.nodejs.org">Node.js</a>&nbsp;(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="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API">WebSocket</a>&nbsp;(two-ways connections) and <a href="https://developer.mozilla.org/en-US/docs/Web/API/EventSource/">EventSource</a>&nbsp;(one-way connections) for <a class="external" href="https://nodejs.org" title="https://nodejs.org/">Node.js</a>&nbsp;Server and Client.</li>
 <li><a href="https://ajf.me/websocket/#libs" title="https://websocket.us/#libs">A more extensive list of frameworks and libraries here</a></li>
</ul>

<h2 class="Related_Topics" id="Related_Topics" name="Related_Topics">Related Topics</h2>

<ul>
 <li><a href="/en-US/docs/AJAX" title="AJAX">AJAX</a>, <a href="/en-US/docs/JavaScript" title="JavaScript">JavaScript</a></li>
</ul>

<h2 id="See_also">See also</h2>

<ul>
 <li><a class="external" href="https://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" title="Server-sent_events">Server-Sent Events</a></li>
</ul>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Version -76 support {{obsolete_inline}}</td>
   <td>6</td>
   <td>{{CompatGeckoDesktop("2.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>11.00 (disabled)</td>
   <td>5.0.1</td>
  </tr>
  <tr>
   <td>Protocol version 7 support {{obsolete_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("6.0")}}<br />
    {{property_prefix("Moz")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td>Protocol version 10 support {{obsolete_inline}}</td>
   <td>14</td>
   <td>{{CompatGeckoDesktop("7.0")}}<br />
    {{property_prefix("Moz")}}</td>
   <td>HTML5 Labs</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Standard - RFC 6455 Support</td>
   <td>16</td>
   <td>{{CompatGeckoDesktop("11.0")}}</td>
   <td>10</td>
   <td>12.10</td>
   <td>6.0</td>
  </tr>
  <tr>
   <td>Usable in Workers</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("37.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Version -76 support {{obsolete_inline}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Protocol version 7 support {{obsolete_inline}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Protocol version 8 support (IETF draft 10) {{obsolete_inline}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile("7.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Standard - RFC 6455 Support</td>
   <td>4.4</td>
   <td>{{CompatGeckoDesktop("11.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>12.10</td>
   <td>6.0</td>
  </tr>
  <tr>
   <td>Usable in Workers</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile("37.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h3 id="Gecko_notes">Gecko notes</h3>

<p>WebSockets support in Firefox is continuing to track the evolving WebSocket specification. Firefox 6 implements version 7 of the underlying protocol, while Firefox 7 implements version 8 (as specified by IETF draft 10). Firefox mobile received WebSocket support in Firefox mobile 7.0.</p>

<h4 id="Gecko_6.0">Gecko 6.0</h4>

<p>Prior to Gecko 6.0 {{geckoRelease("6.0")}}, there was, incorrectly, a <code>WebSocket</code> object that some sites were thinking implied that <code>WebSocket</code> services were not prefixed; this object has been renamed to <code>MozWebSocket</code>.</p>

<h4 id="Gecko_7.0">Gecko 7.0</h4>

<p>Starting in Gecko 7.0 {{geckoRelease("7.0")}}, the <code>network.websocket.max-connections</code> preference is used to determine the maximum number of WebSocket connections that can be open at a time. The default value is 200.</p>

<h4 id="Gecko_8.0">Gecko 8.0</h4>

<p>Starting in Gecko 8.0 {{geckoRelease("8.0")}}, the deflate-stream extension to the WebSocket protocol has been disabled, since it's been deprecated from the specification drafts. This resolves incompatibilities with some sites.</p>

<h4 id="Gecko_11.0">Gecko 11.0</h4>

<p>Prior to Gecko 11.0, both incoming and outgoing messages were limited to 16 MB in size. They may now be up to 2 GB in size. Note, however, that memory limitations (especially on mobile devices) make that a theoretical maximum, not a practical one. In reality, transfers of that size will fail on devices that don't have enough memory.</p>

<p>Additionally, ArrayBuffer send and receive support for binary data has been implemented.</p>

<p>Starting in Gecko 11.0, the WebSocket API is no longer prefixed.</p>
Revert to this revision