Saturday, 22 December 2012


Websockets with ASP.net 4.5 and Visual Studio 2012

In Web on May 1, 2012 by alexjmackey
Web applications are becoming increasingly sophisticated and it is common to need to communicate with various services.
There are a number of options to accomplish this task with probably the most popular being to continually poll a server with XHR requests. Other alternatives exist that delay disconnections. These can be tricky to implement and don’t scale well (sometimes worse than polling as they keep a connection open) so aren’t used as much.
HTTP isn’t really an ideal protocol for performing frequent requests as:
  • It’s not optimized for speed
  • It utilizes a lot of bandwidth for every request with various headers etc sent with every request
  • To keep an application up to date many requests must be sent
  • Provides limited cross domain support (relying on workarounds such as JSONP http://remysharp.com/2007/10/08/what-is-jsonp/)
  • Firewalls & proxys sometimes buffer streaming/long polling solutions increasing latency
  • Long polling & streaming solutions are not very scalable
WebSockets are a new technology that attempts to resolve some of these limitations by:
  • Sending the minimum amount of data necessary
  • Making more efficient usage of bandwidth
  • Providing cross domain support
  • Still operating over HTTP so it can transverse firewalls and proxies
  • Works with some load balancers (TCP l4)
  • Provides support for binary data (note some JavaScript implementations don’t currently support this)
When would web sockets be a suitable protocol for your application?
You might want to consider using web sockets in the following scenarios:
  • Games
  • Real time data
  • Chat applications
  • News tickers
There is a nice set of demos at: http://www.html5rocks.com/en/tutorials/websockets/basics/ and an interesting article that compares a Web Sockets and polling solution in terms of latency & throughput at http://websocket.org/quantum.html.

No comments:

Post a Comment