Pages

Wednesday, August 24, 2011

Overengineering

A while ago I used to be able to VNC from my phone to my desktop to remotely play, pause and change the volume of winamp. I didn't use it often but it was handy.

At some point, my phone just gave up on the VNC connection. I don't know whether it can't handle the screen size (poor iPhone 3g) or if there is an incompatibility in the VNC versions. I did try updating RealVNC and using a different client on my phone but no success.

I had toyed with Java Robot before and figured it would be worth a laugh.

So fired up eclipse and wrote a program that paused, played, turned up the volume and turned down the volume. Fumbled through the Robot javadoc and re-factored it a bit so it looked nice. Got it running fairly quickly.

Next problem, how to control it. I figured html would work for an interface. That means I need to set-up a http server to listen for requests. I was hoping to just fudge through it, read the socket until I got something that looked like a location and push back content.
I wasn't really in the mood to read through the RFC for http so I turned to the Internet.
It came back with NanoHTTPD

I wasn't happy with the way you were expected to subclass it to handle specific URLs so I re-factored it a bit before getting to work.
Put some html together to be served and then it basically fell together.
I love it when you start from the top and bottom of a problem and the middle is just a bit of fiddling around.

So here it is, my winamp remote:

Yup, not much but it made me a happy little coder.

Been wasting most of today re-factoring NanoHTTPD. One of it's selling points is that it is just a single file which was handy for this project, but annoys my sense of organisation. I've split it in 2, one for the pure Http stuff and the other for utilities like turning it into a file browser.
Got rid of the need to consistently spawn new threads, clean up it's stream handling a bit and brought it up to scratch in terms of Java 1.5.

Was wondering if anyone else was interested in this? Should I make the controls configurable so it can control other applications?

No comments:

Post a Comment