简体   繁体   中英

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.

Change

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

to

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM