共用方式為


Introducing the WebSockets Prototype

As we launch our new HTML5 Labs today, this is one of two guest blogs about the first two HTML5 prototypes. It is written by Tomasz Janczuk, a Principal Development Lead in Microsoft’s Business Platform Division.

In my blog post from last summer I wrote about a prototype .NET implementation of two drafts of the WebSockets protocol specification - draft-hixie-thewebsocketprotocol-75 and  draft-hixie-thewebsocketprotocol-76 - making their way through the IETF at that time.

Since then, there have been a number of revisions to the protocol specification, and it is time to revisit the topic. Given the substantial demand for code to experiment with, we are sharing the Windows Communication Foundation server and Silverlight client prototype implementation of one of the latest proposed drafts of the WebSockets protocol: draft-montenegro-hybi-upgrade-hello-handshake-00.

You can read more about the effort and download the .NET prototype code at the new HTML5 Labs site.

What is WebSockets?

WebSockets is one of the HTML 5 working specifications driven by the IETF to define a duplex communication protocol for use between web browsers and servers. The protocol enables applications that exchange messages between the client and the server with communication characteristics that cannot be met with the HTTP protocol.

In particular, the protocol enables the server to send messages to the client at any time after the WebSockets connection has been established and without the HTTP protocol overhead. This contrasts WebSockets with technologies based on the HTTP long polling mechanism available today.

For this early WebSockets prototype we are using a Silverlight plug-in on the client and a WCF service on the server. In the future, you may see HTML5 Labs using a variety of other technologies.

What are we making available?

Along with the downloadable .NET prototype implementation of the WebSocket proposed draft-montenegro-hybi-upgrade-hello-handshake specification, we are also hosting a sample web chat application based on that prototype in Windows Azure here. The sample web chat application demonstrates the following components of the prototype:  

  1. The server side of the WebSocket protocol implemented using Windows Communication Foundation from .NET Framework 4. The WCF endpoint the sample application communicates with implements the draft WebSocket proposal.
  2. The client side prototype implementation consisting of two components:
    1. A Silverlight 4 application that implements the same draft of the WebSocket protocol specification.
    2. A jQuery extension that dynamically adds the Silverlight 4 application above to the page and creates a set of JavaScript WebSocketDraft APIs that delegate their functionality to the Silverlight application using the HTML bridge feature of Silverlight.

The downloadable package contains a .NET prototype implementation consisting of the following components:

  1. A WCF 4.0 server side binding implementation of the WebSocket specification draft.
  2. A prototype of the server side WCF programming model for WebSockets.
  3. Silverlight 4 client side implementation of the protocol.
  4. .NET 4.0 client side implementation of the protocol.
  5. A HTML bridge from the Silverlight to JavaScript that enables use of the prototype from JavaScript applications running in browsers that support Silverlight.
  6. Web chat and stock quote samples.

Given the prototype nature of the implementation, the following restrictions apply:

  1. A Silverlight client (and a JavaScript client, via the HTML bridge) can only communicate using the proposed WebSocket protocol using ports in the range 4502-4534 (this is related to Network Security Access Restrictions applied to all direct use of sockets in the Silverlight platform).
  2. Only text messages under 126 bytes of length (UTF-8 encoded) can be exchanged.
  3. There is no support for web proxies in the client implementation.
  4. There is no support for SSL.
  5. Server side implementation limits the number of concurrent WebSocket connections to 5.

This implementation has been tested to work on Internet Explorer 8 and 9.

Why is this important?

Through access to emerging specifications like WebSockets, the HTML5 Labs sandbox gives you implementation experience with the draft specifications, helps enable faster iterations around Web specifications without getting locked in too early with a specific draft, and gives you the opportunity to provide feedback to improve the specification. This unstable prototype also has the potential to benefit a broad audience.

We want your feedback

As you try this implementation we welcome your feedback and we are looking forward to your comments!

Tomasz

Comments

  • Anonymous
    December 21, 2010
    This is pretty exciting to see, I commented on your related blog post a couple time looking for sample code. Apparently I'm not authorized to post a new message on the Listserv site so I'll comment here. I can't get the demo site to function. I've installed the prototype and after the page loads and I try typing something nothing appears to happen. The status simply remains as Socket Closed. I've tried this in IE and Chrome. The Silverlight object is instantiated properly as far as I can tell. Is it possible that my network firewall is blocking those ports? All other Silverlight applications work fine. Also, unless I'm mistaken, this sample can only use the WebSocketDraft object, and not a browsers native implementation. Is it possible to use the silverlight support as a fallback in the event that a browser doesn't support websockets? I mean, this is the interoperability blog after all ;)

  • Anonymous
    December 21, 2010
    scratch the listserv comment. It just took a while to get authorized.

  • Anonymous
    December 21, 2010
    must have been corporate network problems, works at home now.

  • Anonymous
    December 21, 2010
    This blog was very informative and supportive to us,Thanks.

  • Anonymous
    December 28, 2010
    I have a question. This samlple using html5 websocket and Silverlight on the client side and wcf on the server side. Can we connect websocket to wcf directly (without Silverlight)? What is the advantage of this version instead of I connect a silverlight application (with net.tcp) to wcf service? thank you

  • Anonymous
    December 29, 2010
    Thanks for the fish, but where is the source?

  • Anonymous
    January 29, 2011
    Hi, thanks for blogging. I have discovered Explorer Canvas (code.google.com/.../explorercanvas). With Explorer Canvas, Canvas is supported by IE8. Will there be a similar plug-in for Websockets ? Thanks in advance

  • Anonymous
    February 08, 2011
    Is there a version of Internet Explorer that natively supports WebSockets yet ? Are Microsoft planning on implementing this into IE ? cheers James Mills (prologic)

  • Anonymous
    February 09, 2011
    @James Mills IE does not support WebSockets natively yet, the spec is still changing almost on montly basis so it is still too unstable to become part of supported features in IE

  • Anonymous
    February 10, 2013
    Nice to know about websockets, but I think the same is not yet supported by IE.

  • Anonymous
    February 24, 2013
    Hi We want to use websockets but our clients use Windows XP and IE8 so IE10 is not an option. We would like to use the Siverlight 4 prototype. We know it is no longer supported, but anyway can you please provide a download link for that? Thank you!

  • Anonymous
    February 24, 2013
    Your contact form is broken. When I clic the Send button the server says [HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]

  • Anonymous
    February 25, 2013
    @Javier Thanks for bringing up the issue with the contact form, we will make sure this is fixed. Regarding the prototype, we cannot share the code that is now deprecated and had not been designed for production at all.

  • Olivier
  • Anonymous
    February 25, 2013
    @Olivier Thank you for your response. What would you recommend for websocket-like functionality on IE8? We are looking at some Comet implementations and would appreciate your input. Javier