virattara virattara - 5 months ago 42
Node.js Question

Socket.io client not receiving message event

My project's skeleton is of express-generator thus used this workaround:here

SERVER:

io.on('connection', function(socket){
socket.on('message', function(msg){
io.emit('message', msg);
});
});


CLIENT:(src for socket included)

var socket = io.connect('//localhost:5000');

function op(){
socket.emit('message', $('input[name=yolo]:checked', '#myForm').val());
};

socket.on('message', function(msg){
console.log("oo");
$("input[value=msg]").attr('disabled',true);
alert($("input[value=msg]").val());
});


FORM

form(action='' id="myForm")
///form inputs
input(type="submit" value="book" onclick="op()")



  1. Connection is made on both sides verified.

  2. Message is received by the server but it isn't emitting it for the client side socket.on('message'... to trigger.

  3. Tested every step only the last socket.on('message'.. not triggering.


Answer

Found the problem. I was using Firefox and it's just not working with Socket.io shifted to chrome and everything is working fine.