I've created a simple chat application as recommended (which works fine), but I'm having trouble figuring out how to launch a jQuery-function across web sockets with Socket.IO.
For example, I have a button to click:
<button id="button">
Click me!
</button>
I would like my the button to execute a function when it's clicked:
$("button").click(function() {
doSomething();
});
Here is an example of what I have on the client side
var socket = io.connect('http://localhost:3000');
function doSomething() {
$('body').css({
background: "red"
});
}
Here is what I have on the server side (my server.js file) - I think this might be causing part of the issue:
var io = require('socket.io'),
connect = require ('connect');
var app = connect().use(connect.static('public')).listen(3000);
var commands = io.listen(app);
commands.sockets.on('connection', function (socket){
// Possibly insert handler here?
});
Just in case I wasn't clear on the purpose - I'd like that when the button is clicked, to have the body background of all connected clients turn red.