Integrasi Komputer    
   
Daftar Isi
(Sebelumnya) Website governanceWebTrain (Berikutnya)

WebSocket

WebSocket is a web technology providing full-duplex communications channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API for the WebIDL language is being standardized by the W3C.

WebSocket is designed to be implemented in web browsers and web servers, but it can be used by any client or server application. The WebSocket Protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request.[1] The WebSocket protocol makes possible more interaction between a browser and a web site, facilitating live content and the creation of real-time games. This is made possible by providing a standardized way for the server to send content to the browser without being solicited by the client, and allowing for messages to be passed back and forth while keeping the connection open. In this way a two-way (bi-directional) ongoing conversation can take place between a browser and the server. A similar effect has been achieved in non-standardized ways using stop-gap technologies such as Comet.

In addition, the communications are done over TCP port number 80, which is of benefit for those environments which block non-standard Internet connections using a firewall. WebSocket protocol is currently supported in several browsers including Google Chrome, Internet Explorer, Firefox, Safari and Opera. WebSocket also requires web applications on the server to support it.

Contents

Technical overview

Like TCP, WebSocket provides for full-duplex communication. Websocket differs from TCP in that it enables a stream of messages instead of a stream of bytes. Before WebSocket, port 80 full-duplex communication was attainable using Comet channels; however, comet implementation is nontrivial, and due to the TCP handshake and HTTP header overhead, it is inefficient for small messages. WebSocket protocol aims to solve these problems without compromising security assumptions of the web.

Browser Implementation

A secure version of the WebSocket protocol is implemented in Firefox 6 (named MozWebSocket),[2] Google Chrome 14,[3] Opera 12.10 and Internet Explorer 10.[4]

An older, less secure version of the protocol was implemented in Opera 11 and Safari 5, as well as the mobile version of Safari in iOS 4.2.[5] Also, the BlackBerry Browser in OS7 implements WebSocket.[6] Although there are no known exploits, it was disabled in Firefox 4 and 5,[7] and Opera 11.[8]

WebSocket protocol handshake

To establish a WebSocket connection, the client sends a WebSocket handshake request, and the server sends a WebSocket handshake response, as shown in the following example:

GET /mychat HTTP/1.1Host: server.example.comUpgrade: websocketConnection: UpgradeSec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==Sec-WebSocket -Protocol: chatSec-WebSocket-Version: 13Origin: http://example.com

Server response:

HTTP/1.1 101 Switching ProtocolsUpgrade: websocketConnection: UpgradeSec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=Sec-WebSo cket-Protocol: chat

The handshake resembles HTTP, but actually isn't.[clarification needed] It allows the server to interpret part of the handshake request as HTTP, then switch to WebSocket.

Note that each line ends with an EOL (end of line) sequence, \n or \r\n. There must be a blank line at the end.

The client sends a Sec-WebSocket-Key which is base64 encoded. To form a response, the magic string 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 is appended to this (undecoded) key. The resulting string is then hashed with SHA-1, then base64 encoded. Finally, the resulting reply occurs in the header Sec-WebSocket-Accept.

Details of Sec-WebSocket-Key to Sec-WebSocket-Accept :

  • x3JJHMbDL1EzLkh9GBhXDw==258EAFA5-E914 -47DA-95CA-C5AB0DC85B11 string hashed by SHA-1 gives 0x1d29ab734b0c9585240069a6e4e3e91b61da1 969 hexadecimal value.
  • Encoding the SHA-1 hash by Base64 (using the binary of the SHA-1) yields HSmrc0sMlYUkAGmm5OPpG2HaGWk=, which is the Sec-WebSocket-Accept value.

Once the connection is established, the client and server can send WebSocket data or text frames back and forth in full-duplex mode. The data is minimally framed, with a small header followed by payload. WebSocket transmissions are described as "messages", where a single message can optionally be split across several data frames. This can allow for sending of messages where initial data is available but the complete length of the message is unknown (it sends one data frame after another until the end is reached and marked with the FIN bit). With extensions to the protocol, this can also be used for multiplexing several streams simultaneously (for instance to avoid monopolizing use of a socket for a single large payload).

Proxy traversal

WebSocket protocol client implementations try to detect if the user agent is configured to use a proxy when connecting to destination host and port and, if it is, uses HTTP CONNECT method to set up a persistent tunnel.

While the WebSocket protocol itself is unaware of proxy servers and firewalls, it features an HTTP-compatible handshake so that HTTP servers can share their default HTTP and HTTPS ports (80 and 443) with a WebSocket gateway or server. The WebSocket protocol defines a ws:// and wss:// prefix to indicate a WebSocket and a WebSocket Secure connection, respectively. Both schemes use an HTTP upgrade mechanism to upgrade to the WebSocket protocol. Some proxy servers are harmless and work fine with WebSocket; others will prevent WebSocket from working correctly, causing the connection to fail. In some cases, additional proxy server configuration may be required, and certain proxy servers may need to be upgraded to support WebSocket.

If unencrypted WebSocket traffic flows through an explicit or a transparent proxy server on its way to the WebSocket server, then, whether or not the proxy server behaves as it should, the connection is almost certainly bound to fail today (as WebSocket become more mainstream, proxy servers may become WebSocket aware). Therefore, unencrypted WebSocket connections should be used only in the simplest topologies.[9]

If an encrypted WebSocket connection is used, then the use of Transport Layer Security (TLS) in the WebSocket Secure connection ensures that an HTTP CONNECT command is issued when the browser is configured to use an explicit proxy server. This sets up a tunnel, which provides low-level end-to-end TCP communication through the HTTP proxy, between the WebSocket Secure client and the WebSocket server. In the case of transparent proxy servers, the browser is unaware of the proxy server, so no HTTP CONNECT is sent. However, since the wire traffic is encrypted, intermediate transparent proxy servers may simply allow the encrypted traffic through, so there is a much better chance that the WebSocket connection will succeed if WebSocket Secure is used. Using encryption is not free of resource cost, but often provides the highest success rate.

A mid-2010 draft (version hixie-76) broke compatibility with reverse-proxies and gateways by including 8 bytes of key data after the headers, but not advertising that data in a Content-Length: 8 header.[10] This data was not forwarded by all intermediates, which could lead to protocol failure. More recent drafts (e.g., hybi-09[11]) put the key data in a Sec-WebSocket-Key header, solving this problem.

URI scheme

The WebSocket protocol specification defines two new URI schemes, ws: and wss:,[12] for unencrypted and encrypted connections respectively. Apart from the scheme name, the rest of the URI components are defined to use URI generic syntax.[13]

Browser support

All the latest browsers except Android browser support the latest specification (RFC 6455) of the WebSocket protocol. A detailed protocol test suite report[14] lists the conformance of those browsers to specific protocol aspects.

Firefox 4[15] and Opera 11[16] originally supported the outdated draft-ietf-hybi-thewebsocketprotocol- 00 WebSocket, but later disabled the protocol by default due to security issues. Chrome also planned to disable the WebSocket if actual exploit code appeared before the protocol was revised.[17]

Implementation status
ProtocolInternet ExplorerFirefox[18] (PC)Firefox (Android)Chrome (PC, Mobile)Safari (Mac, iOS)Opera (PC, Mobile)Android Browser
hixie-75   45.0.0  
hixie-76
hybi-00
 4.0 (disabled) 65.0.111.00 (disabled) 
7 hybi-07 6[19]1     
8 hybi-10 7[20]1714[21]   
13 RFC 645510[22]111116[23]612.10[24] 

1 Gecko-based browsers versions 6–10 implement the WebSocket object as "MozWebSocket",[25] requiring extra code to integrate with existing WebSocket-enabled code.

Server side

Experimental extensions

There is also a command-line switch for Google Chrome (--enable-websocket-over-spdy) that enables an early experimental implementation of WebSocket over SPDY.[27]

Development

The WebSocket echo service hosted by websocket.org offers a simple way to get started with WebSocket development. Using the Google Chrome Developer Tools developers can inspect the WebSocket handshake as well as the WebSocket frames.[28]

See also

References

  1. ^ RFC 6455#section-1.7
  2. ^ Dirkjan Ochtman (May 27, 2011). "WebSocket enabled in Firefox 6". Mozilla.org. https://developer.mozilla.org/en/WebS ockets. Retrieved 2011-06-30.
  3. ^ "Chromium Web Platform Status". http://www.chromium.org/developers/we b-platform-status. Retrieved 2011-08-03.
  4. ^ "WebSockets (Windows)". Microsoft. 2012-09-28. http://msdn.microsoft.com/en-us/libra ry/ie/hh673567(v=vs.85).aspx. Retrieved 2012-11-07.
  5. ^ Katie Marsal (November 23, 2010). "Apple adds accelerometer, WebSockets support to Safari in iOS 4.2". AppleInsider.com. http://www.appleinsider.com/articles/ 10/11/23/apple_adds_accelerometer_web sockets_support_to_safari_in_ios_4_2. html. Retrieved 2011-05-09.
  6. ^ "Web Sockets API". RIM. http://docs.blackberry.com/en/develop ers/deliverables/29271/Web_Sockets_su pport_1582781_11.jsp. Retrieved 8 July 2011.
  7. ^ Chris Heilmann (December 8, 2010). "WebSocket disabled in Firefox 4". Hacks.Mozilla.org. http://hacks.mozilla.org/2010/12/webs ockets-disabled-in-firefox-4/. Retrieved 2011-05-09.
  8. ^ Aleksander Aas (December 10, 2010). "Regarding WebSocket". My Opera Blog. http://my.opera.com/chooseopera/blog/ 2010/12/10/regarding-websocket. Retrieved 2011-05-09.
  9. ^ "How Web Sockets Interact With Proxy Servers". Infoq.com. http://www.infoq.com/articles/Web-Soc kets-Proxy-Servers. Retrieved 2011-12-10.
  10. ^ "WebSocket -76 is incompatible with HTTP reverse proxies". Ietf.org. 2010-07-06. http://www.ietf.org/mail-archive/web/ hybi/current/msg02149.html. Retrieved 2011-12-10.
  11. ^ "The WebSocket protocol, draft hybi-09". June 13, 2011. http://tools.ietf.org/html/draft-ietf -hybi-thewebsocketprotocol-09. Retrieved June 15, 2011.
  12. ^ "IANA Uniform Resource Identifer (URI) Schemes". Iana.org. 2011-11-14. http://www.iana.org/assignments/uri-s chemes.html. Retrieved 2011-12-10.
  13. ^ "draft-hixie-thewebsocketprotocol-76 - The WebSocket protocol". Tools.ietf.org. http://tools.ietf.org/html/draft-hixi e-thewebsocketprotocol. Retrieved 2011-12-10.
  14. ^ "WebSockets Protocol Test Report". Tavendo.de. 2011-10-27. http://autobahn.ws/testsuite/reports/ clients/index.html. Retrieved 2011-12-10.
  15. ^ "How to enable WebSockets in Firefox". Developer.mozilla.org. 2011-09-30. https://developer.mozilla.org/en/WebS ockets. Retrieved 2011-12-10.
  16. ^ "Opera 11 release notes, with procedure to re-enable Web Sockets". My.opera.com. 2010-12-17. http://my.opera.com/ODIN/blog/2010/12 /17/new-html5-features-in-opera-11. Retrieved 2011-12-10.
  17. ^ Issue 5643005: Disable WebSocket by default[dead link]
  18. ^ "WebSockets (support in Firefox)". Developer.mozilla.org. 2011-09-30. https://developer.mozilla.org/en/WebS ockets. Retrieved 2011-12-10.
  19. ^ "Bug 640003 - WebSockets - upgrade to ietf-06". Bugzilla.mozilla.org. https://bugzilla.mozilla.org/show_bug .cgi?id=640003. Retrieved 2011-12-10.
  20. ^ WebSockets - upgrade to ietf-07>
  21. ^ "Chromium bug 64470". Code.google.com. 2010-11-25. http://code.google.com/p/chromium/iss ues/detail?id=64470. Retrieved 2011-12-10.
  22. ^ "WebSockets in Windows Consumer Preview". IE Engineering Team. 2012-03-19. http://blogs.msdn.com/b/ie/archive/20 12/03/19/websockets-in-windows-consum er-preview.aspx. Retrieved 2012-07-23.
  23. ^ "WebKit Changeset 97247: WebSocket: Update WebSocket protocol to hybi-17". Trac.webkit.org. http://trac.webkit.org/changeset/9724 9. Retrieved 2011-12-10.
  24. ^ "A hot Opera 12.50 summer-time snapshot". Opera Developer News. http://my.opera.com/ODIN/blog/2012/08 /03/a-hot-opera-12-50-summer-time-sna pshot. Retrieved 2012-08-03.
  25. ^ "WebSockets - MDN". Developer.mozilla.org. 2011-09-30. https://developer.mozilla.org/en/WebS ockets. Retrieved 2011-12-10.
  26. ^ http://blogs.microsoft.co.il/blogs/id of/archive/2012/03/06/what-s-new-in-w cf-4-5-websocket-support-part-2-of-2. aspx
  27. ^ "Daftar/Tabel -- Chromium Command Line Switches". Peter.sh. http://peter.sh/experiments/chromium- command-line-switches/. Retrieved 2011-12-10.
  28. ^ "Inspecting WebSocket Traffic with Chrome Developer Tools". Peter Moskovits. http://blog.kaazing.com/2012/05/09/in specting-websocket-traffic-with-chrom e-developer-tools/.

External links

(Sebelumnya) Website governanceWebTrain (Berikutnya)