Friday, 1 June 2012

Websockets and the Play Framework

You'll find lots of posts about why websockets are interesting - many of them from people demonstrating them using the Play Framework. I am not going to go over any that ground but I am going to mention some example code I pulled together to demonstrate websockets in Play:

Most of the older posts are from at least 6 months ago. While the theory is right, the code examples will no longer work because the websockets specification (and hence the browser and framework implementation) has changed. In fact, I have not seen a Play 1.2.5 example yet. So here is one, mostly cobbled together from other people's older code. Shoulders of giants and all that.

Anyway, for this example you will need Play 1.2.5rc3 or above and Chrome 19+ or Firefox 12+. I haven't tested it in Java 5 but I wouldn't be surprised if Java 6 is also a requirement.

The example is the pretty basic: browser sends an event over the websocket, controller at the server end echoes it back to browser and everyone else also looking at the example page. The bit to watch out for is the handling of the event queue. The message originator has the event echoed straight back. For everyone else, the message is added to an event queue which triggers the echo via a different mechanism.

The code is over-commented so hopefully other folk can benefit from my stepping through it all.

Configure the window close buttons in Ubuntu 12.04

One thing I really don't like about Ubuntu if the insistence in putting the close window button in the top left. I don't know if this is a Linux thing, but I'm sure older versions defaulted to close in the top right.

Anyway, you can easily change it.

* install gconf-editor
* navigate to /apps/metacity/general/
* find button_layout and change it to whatever you like

The key to the positioning of the buttons is the colon. I went with:
because I don't really care about maximize. Everything to the right of the colon is floated right.

Another tweak worth considering if you're a keyboard shortcut person is rebinding "Key to show HUD" in the Keyboard config screen. That is the one which, if your experience is anything like mine, is capturing your keypress when you try and alt-tab around.

Since 12.10 it seems the gconf-editor setting is sometimes ignored. You can move everything by running this on the command line:
sudo gsettings set org.gnome.desktop.wm.preferences button-layout ":minimize,maximize,close"