Sending realtime data with node.js and socket.io

Here's my code:

Node:

var express = require('express')
	, app = express()
	, server = require('http').createServer(app)
  	, io = require('socket.io').listen(server)
	, dgram = require('dgram');

server.listen(5000);

var client = dgram.createSocket('udp4');
var message = new Buffer("100 101 102");

app.use(express.static(__dirname + '/'));

io.sockets.on('connection', function(socket) {
	console.log("Server Connected");
	socket.on('message', function(data) {
		console.log(data);
		client.send(message, 0, message.length, 8888, '192.168.1.1')
	});
});

relevant html javascript:

<script src="/socket.io/socket.io.js"></script>
<script>
socket = io.connect('http://localhost');
$(window).click(function() {
	sendData(100, 101, 102);
});
</script>

I have an ethernet shield that simply changes the color of an led. Seems to work fine when I run it on my machine, but if I try to run it on heroku or nodejitsu, it returns errors. Heroku says it can't find Socket.io, and nodejitsu runs but never sends the data and crashes after a couple requests don't go through. Does anyone have experience with node.js and socket.io? I'm very new to it. Is there a better approach for realtime data transfer from a website to an ethernet arduino?

Are you using UDP? What OS are you using on the computer? I have some C code for Linux that works ok. If you are using Linux, let me know and I'll modify it to post here.

edit: I use an Apache server running the UDP code with a MySQL database linking the two.

I'm currently working on a similar project, well, I should say, continuing to work on.
My main aim is to provide next to real time remote monitoring, alarming and trending of a remote site and while I have it working well via traditional HTTP protocol I have been playing around with publishing from the Arduino to PubNub which clients can subscribe to.

I intially tried SSE, (Server Sent Events) but that doesn't work from my standard hosted site.
I have Nod.js on my mac but again I can't install it on my hosted site either.

I made a small test the other day where the Arduino publishes data to PubNub, works quite well.
The data from the Arduino to PubNub is still HTTP, but the cleint side is using server push technology.
I would like to see that it may be possible to send from Arduino to PubNub via UPD, but that is not available as yet.
The beaut thing with this topology that it is designed for fairly high throughput of data on a one to many relationship.
And it is just what I need for having alarm conditions being sent without polling.

Take a look at PubNub, especially the developers section, PubNub Developers: Build Powerful Real-Time Apps Easily | PubNub

Would be interested to learn more about what it is you are wanting to do.
Presently working on new statistical gauges, all javascript, eeew.


Paul

I'm using Heroku for hosting as they recently added support for websockets. I'm on a Windows system. Right now the main goal is to just control a rgb led over a website. Similar to the phillips smart hue bulbs (https://www.meethuom/en-US). I need it to be quick and realtime, so when I drag my finger across an rgb spectrum it shows all of the colors that I hit on my way from point a to point b.