Skip to content

Commit

Permalink
Fixed socket.io related issue
Browse files Browse the repository at this point in the history
  • Loading branch information
robrighter committed Dec 31, 2011
1 parent 16069b9 commit 6794b07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
18 changes: 9 additions & 9 deletions templates/app/server.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ server.listen( port);


//Setup Socket.IO //Setup Socket.IO
var io = io.listen(server); var io = io.listen(server);
io.on('connection', function(client){ io.sockets.on('connection', function(socket){
console.log('Client Connected'); console.log('Client Connected');
client.on('message', function(message){ socket.on('message', function(data){
client.broadcast(message); socket.broadcast.emit('server_message',data);
client.send(message); socket.emit('server_message',data);
}); });
client.on('disconnect', function(){ socket.on('disconnect', function(){
console.log('Client Disconnected.'); console.log('Client Disconnected.');
}); });
}); });




Expand Down
8 changes: 2 additions & 6 deletions templates/js/script.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@


$(document).ready(function() { $(document).ready(function() {


socket = new io.Socket(null, { var socket = io.connect();
port: 8081
,transports: ['websocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']
});
socket.connect();


$('#sender').bind('click', function() { $('#sender').bind('click', function() {
socket.emit('message', 'Message Sent on ' + new Date()); socket.emit('message', 'Message Sent on ' + new Date());
}); });


socket.on('message', function(data){ socket.on('server_message', function(data){
$('#reciever').append('<li>' + data + '</li>'); $('#reciever').append('<li>' + data + '</li>');
}); });
}); });

0 comments on commit 6794b07

Please sign in to comment.