javascript - Socket.io client not receiving message event -
my project's skeleton of express-generator used workaround:here
server:
io.on('connection', function(socket){ socket.on('message', function(msg){ io.emit('message', msg); }); });
client:(src 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()")
connection made on both sides verified.
message received server isn't emitting client side socket.on('message'... trigger.
- tested every step 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); }); });
Comments
Post a Comment