javascript - Node.js, Socket.io emit not working -
i making website in socket.io
. emit
method not working in code. can't see errors in code. here server code.
var io = require("socket.io").listen(server); //some external codes running server in node.js io.on("connection", function(socket) { //this line working. console.log("socket connected."); io.on("requestnewmap", function(data) { //create new map object in here. io.emit("responsenewmap", { mapdata: map }); }); });
and client side javascript
code.
var socket = io(); socket.on("responsenewmap", function(data) { var map = data.mapdata; //draw map in canvas's context. }); //setinterval runs method every 2 seconds. function requestnewmap() { socket.emit("requestnewmap"); }
this part wrong:
io.on("requestnewmap", function(data) { //create new map object in here. io.emit("responsenewmap", { mapdata: map }); });
i use socket
there in:
socket.on("requestnewmap", function(data) { //create new map object in here. socket.emit("responsenewmap", { mapdata: map }); });
i think io.emit
should work fine, send response every connected client, io.on('requestnewmap',...)
won't work since requestnewmap
not io
standard event.
Comments
Post a Comment