WebSocket: Bringing TCP to the browser

The WebSocket standard is almost finalized. However, WebSocket itself is offering “just” a (data) pipe. WebSocket is well suited to bring event- or data-driven applications to the browser. A valid example would a Web UI for a JMS or AMQP application. With help of the Kaazing Gateway this is possible! As said before, you are basically able to bring any TCP- or UDP-based application to the web.

A simple TCP-based echo server

Since the WebSocket client API itself is not enough (to build a “real” application), we need some (existing) backend, or server. A very simple example would be to bring a (TCP) echo server to the browser, via WebSocket:

var net = require('net');

var server = net.createServer(function (socket) {

  // "on data" event listener:
  socket.on('data', function(data) {

    console.log('Got this data: ' + data)

    // Echo:
    socket.write('You said: ' + data);
  });
});

server.listen(1337, '127.0.0.1');

The above code is a VERY simple “EchoServer” that runs on port “1337″. It is in Node.js. The code is borrowed from their website.

Bring it to the Web

To be able to access this TCP server with a WebSocket application you need to add the following configuration to the Kaazing WebSocket Gateway:

<service>
  <accept>ws://localhost:8000/echo</accept>
  <connect>tcp://localhost:1337/</connect>
  <type>proxy</type>
  <cross-site-constraint>
    <allow-origin>*</allow-origin>
  </cross-site-constraint>
</service>

The entry point for the echo server is the ws://localhost:8000/echoURL. The Gateway connects the WebSocket connection to the backend (check the tcp port). The connection to the echo server is straightforward. The following shows a pretty simple JavaScript program, that opens a WebSocket connection in order to send and receive data from the underlying TCP server:

var websocketConnection = new WebSocket("ws://localhost:8000/echo");
websocketConnection.onopen = function(ev) {
	console.log('Connected to the echo service')
};
websocketConnection.onmessage = function(event) {
  var payload = event.data;
  displayEcho(payload);
};
...
websocketConnection.send("Hello Echo Server");
...

This is obviously a simple example, but it clearly shows the power of WebSocket! Give it a try!

If you are interested in HTML5 and WebSocket, check out the Kaazing Gateway! BTW. Kaazing is hiring

last.fm on my iPod touch

I am really happy, that I could get an iPod Hi-Fi for my home office (no, I bought it myself ;-) ).
With last.fm available for iPhone / iPod, it is really cool to listen to my favorite stations via iPod on that Hi-Fi thing. I love the sound! The software (last.fm for iPod) was a bit buggy in the past. Now, I guess early this week, they released version 1.0.2 and I have to say, it works!

Oh yeah, the last.fm software is for free, but I had to upgrade to the recent iPhone/iPod 2.0 software. Not a big deal at all…

Anyway, last.fm is (for me) much better than traditional radio. Well, for football (I mean soccer…) I still prefer a traditional radio station, if I am not watching it on pay-tv ;-)

Thunderbird vs. Gmail (Desktop vs. Web)

I am using Gmail for all of my (Apache) mailing lists, my private stuff, and sometimes I write emails to team-mates via my private Gmail account.
For 99% of my corp. emails, I am using Thunderbird, which is a FAT CLIENT.

I like using the Web-based email, but sometimes, the traffic is slow (depends on your connection, sure) and than… switching folders or searching can be a PITA. That is not the case in Thunderbird. That FAT CLIENT is working offline too.

Now there are “persistence frameworks”, such as Google Gears, which offer your a great deal to run your web-app offline.

But even with that, sometimes it just feels better to use a FAT CLIENT, IMO.

Using Web-Mail is common; word-processing or spreatsheets are new, but they are more and more used, in an online version.

All this is OK, the move is from the desktop to the WEB. Fine so far, but I’d never want to use my IDE (JDeveloper and Eclipse) via a Web-Browser :-)
That would be just too much. I hope that this isn’t the next trend :-)