问题
I am fetching the chat history from db and displaying it to the user. The data is successfully reading data from the mongodb but whenever I'm using io.sockets.emit then client side is unable to receive any data..
Below is the server.js code
io.sockets.on('connection',function(socket){
socket.on('getChatHistory',function(data,callback){
var query = { liveId: "1234" };
db.collection("chat").find(query).toArray(function(err, result) {
if (err) throw err;
console.log(result, " Result of Find query ...");
io.sockets.emit('showChatHistory', result);
});
});
});
Console is displaying the correct result and I am hoping to fetch the data on client side...
I'm capturing the data on client side in the following format:
{
socket.on('showChatHistory',function(data){
console.log(data, " data.......");
});
The following image is the output displayed after fetching record
and when i followed the error. It led to the following file
来源:https://stackoverflow.com/questions/60540668/io-sockets-emit-unable-to-send-info-from-server-side-to-client-side