Permalink
Browse files

Fixed socket.io related issue

  • Loading branch information...
1 parent 16069b9 commit 6794b07ca6efb44995b752df5cc2563f2a67b1c9 @robrighter committed Dec 31, 2011
Showing with 11 additions and 15 deletions.
  1. +9 −9 templates/app/server.js
  2. +2 −6 templates/js/script.js
View
18 templates/app/server.js
@@ -38,15 +38,15 @@ server.listen( port);
//Setup Socket.IO
var io = io.listen(server);
-io.on('connection', function(client){
- console.log('Client Connected');
- client.on('message', function(message){
- client.broadcast(message);
- client.send(message);
- });
- client.on('disconnect', function(){
- console.log('Client Disconnected.');
- });
+io.sockets.on('connection', function(socket){
+ console.log('Client Connected');
+ socket.on('message', function(data){
+ socket.broadcast.emit('server_message',data);
+ socket.emit('server_message',data);
+ });
+ socket.on('disconnect', function(){
+ console.log('Client Disconnected.');
+ });
});
View
8 templates/js/script.js
@@ -3,17 +3,13 @@
$(document).ready(function() {
- socket = new io.Socket(null, {
- port: 8081
- ,transports: ['websocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']
- });
- socket.connect();
+ var socket = io.connect();
$('#sender').bind('click', function() {
socket.emit('message', 'Message Sent on ' + new Date());
});
- socket.on('message', function(data){
+ socket.on('server_message', function(data){
$('#reciever').append('<li>' + data + '</li>');
});
});

0 comments on commit 6794b07

Please sign in to comment.