socket.io应用程序到网络聊天

socket.io应用程序到网络聊天,io,websocket,socket.io,chat,Io,Websocket,Socket.io,Chat,我正在使用socket.io从用户(应用程序)到管理员(到浏览器)聊天。此处,管理员消息已正确发送给用户,但管理员未收到用户消息。我正在关注聊天应用程序。还有应用程序对应用程序的聊天,这对我来说很好 这是我的服务器端代码 socket.on('send:message', function (msg) { console.log("send:message", msg); if (msg.orderChat) var q = models.orderChat.create(m

我正在使用socket.io从用户(应用程序)到管理员(到浏览器)聊天。此处,管理员消息已正确发送给用户,但管理员未收到用户消息。我正在关注聊天应用程序。还有应用程序对应用程序的聊天,这对我来说很好

这是我的服务器端代码

  socket.on('send:message', function (msg) {
    console.log("send:message", msg);
    if (msg.orderChat) var q = models.orderChat.create(msg)
    else var q = models.chat.create(msg)
    q.then(function (ret) {
        console.log(ret.get({ plain: true }));
        socket.in(msg.chat_room).emit('send:message', msg);
        //socket.emit('send:message', msg);
    }).catch(function (err) {
        console.log(err);
        socket.in(msg.chat_room).emit('send:message', 'Server Error');
    });
});
socket.on('send:message', function (msg) {
    username = $('.pchat').attr('data-username');
    console.log(msg);
    $("#chat_div_" + username).chatbox("option", "boxManager").addMsg(username, msg.message);
})
这是我的客户端代码

  socket.on('send:message', function (msg) {
    console.log("send:message", msg);
    if (msg.orderChat) var q = models.orderChat.create(msg)
    else var q = models.chat.create(msg)
    q.then(function (ret) {
        console.log(ret.get({ plain: true }));
        socket.in(msg.chat_room).emit('send:message', msg);
        //socket.emit('send:message', msg);
    }).catch(function (err) {
        console.log(err);
        socket.in(msg.chat_room).emit('send:message', 'Server Error');
    });
});
socket.on('send:message', function (msg) {
    username = $('.pchat').attr('data-username');
    console.log(msg);
    $("#chat_div_" + username).chatbox("option", "boxManager").addMsg(username, msg.message);
})
更新
当用户在同一浏览模式下聊天,而不是在交叉浏览模式下聊天时,代码也可以正常工作

我相信在这里提供的代码之外可能存在bug

在您的服务器端,我已更改:

    socket.in(msg.chat_room).emit('send:message', msg);

不过,如果你能提供完整的代码,我将能够帮助你进一步排除故障