0

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.
Community
  • 1
  • 1
line-segment
  • 369
  • 5
  • 14

2 Answers2

0

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

line-segment
  • 369
  • 5
  • 14
-1

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);
});
});
Heartz
  • 1
  • 1
  • 2