WebSockets

The WebSocket API is yet another new technology introduced together with HTML5. It allows two way communication between a web page (JavaScript) and a TCP socket. There are several differences compared to normal sockets though.

  • Only sockets on the page’s web server can be called.
  • Communication goes through the web server socket.
  • Both server and browser must support it.

The application on the server that wishes to communicate through the WebSocket opens a regular TCP socket. Then there is a handshake procedure that must be followed before data can be sent and received.

Support for WebSockets in browsers are still a bit lacking. Internet Explorer 9 does not support it. Firefox 6.0 supports it but calls the object MozWebSocket. Older browsers can fake support by using Flash. There are JavaScript libraries that can abstract this for us.

I tried to use WebSockets myself without the aid of libraries. Unfortunately, this turned out to be harder than expected. I wrote a Perl script to act as the server side. This would receive the headers from the client and the client would also react to me closing the socket on the server. However, I did not manage to properly shake hands with the client and no data could be sent. Currently I feel it’s not worth the effort to dig deeper.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s