Realtime Web Data with WebSockets

For years there was no native support for passing data from a web server to a client. The client would always have to initiate an HTTP request to pull data down from the server. This made realtime applications almost impossible. There have been some clever hacks to work around this limitation such as long-polling but there has never been a true way to push unsolicited information from the server until now. Enter WebSockets. WebSocket is a protocol providing full-duplex communication channels over a single TCP connection. The WebSocket protocol has recently been adopted by all major internet browsers and is part of HTML5. Using WebSockets, a web server can push data to it's connected clients in realtime. a WebSocket also allows the client to pass data over the connection to the server making it a bi-directional channel. WebSockets are initiated just like any other HTTP connection but after the connection is established it is "upgraded" to a TCP connection.

As I mentioned earlier, there are other options that serve the same function as WebSockets but they have been less effective and/or less widely implemented.

  1. long-polling: This is more of a hack than a standard. It relies on an http connection's timeout limit. But, unlike WebSockets, the connection must be reset periodically after a timeout occurs, or after a succesful server to client message has occured.
  2. HTTP Streaming: Similar in implementation to long-polling. HTTP streaming takes advantage of the initial HTTP connection established by the client when a request for a web resource is made. Instead of closing this connection when all the data has been sent, the connection is left open. This allows the server to tack on extra data that will be streamed to the client as part of the same request. This data, usually JavaScript is executed immediately by the browser. Unfortunately, like long-polling the browser may eventually trigger a timeout which will close the connection.
  3. Flash XMLSocket relay: This method relies on embedding a Flash application inside the webpage, enough said.
  4. server-sent events (SSE): SSE is another HTML5 specification. While SSEs seems like a winner at first glance, they are lacking support in some of the major browsers at this time. SSEs also only send data in one direction from server to client making them less versatile.

Some examples of where WebSockets can improve your user experience by delivery realtime data are:

  1. Instant Messaging
  2. Online Games
  3. Social Media Feeds
  4. Analytics
  5. Document Editing Collaboration

Want to Learn More?

This is just a sample of what we can do. We have 15 years of experience working in nearly every technology and industry. Whatever you are doing, we've done it and are prepared to tackle your project. Reach out and we will discuss it with you.