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()")
Connection is made on both sides verified.
Message is received by the server but it isn't emitting it for the client side socket.on('message'... to trigger.
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.