Monday, March 12, 2012

First (Failed) Attempt at Web Sockets in Dart

Tonight, I hope to evaluate how much detail I ought to devote to websockets in Dart for Hipsters. Currently, I plan to mention them in passing in a high-level HTML5 introduction, but perhaps they are worth more.

I normally use faye for my websocket needs, but that won't be of much use to me in Dart as I would have to implement the client-side library. That seems... involved. I briefly explore writing a server in Dart itself (the HTTP server from this dartlang.org article works nicely), but unfortunately websockets are not available on the server-side. Per a tracker issue, websockets are not available in dart:io and dart:html is not available in server-side dart.

So I stick with what I know and install a node.js + express.js server. Along with that, I install WebSocket-Node as it seems to be a solid pure WebSocket implementation. The package.json for my sample app is:

But that fails. I see not errors in the client, but no messages logged on the server side. I am forced to call it a night here. I will pick back up tomorrow -- hopefully I can see this through. Regardless, since WebSocket is not yet implemented in dart:html, it seems as though WebSockets can wait until the 1.1 edition of the book.

Looks like that bug can be closed. I tried a recent build and am able to construct websockets from dart:html: http://japhr.blogspot.com/2012/03/dart-websockets-take-2.html (toward the bottom of that post).