Node.js 无法使用reactjs中的soket.io从服务器获取数据

Node.js 无法使用reactjs中的soket.io从服务器获取数据,node.js,reactjs,sockets,real-time,Node.js,Reactjs,Sockets,Real Time,我试图在react项目中使用soket.io执行一些实时任务,但它显示已连接,但没有接收到任何内容。 下面是我到目前为止写的代码 import io from 'socket.io-client'; const socket = io('http://xx.xxx.xx.xxx:4000'); componentDidMount(){ socket.on('connect', () => { console.log(socket.connected);// con

我试图在react项目中使用soket.io执行一些实时任务,但它显示已连接,但没有接收到任何内容。 下面是我到目前为止写的代码

import io from 'socket.io-client';
const socket = io('http://xx.xxx.xx.xxx:4000');

componentDidMount(){
    socket.on('connect', () => {
        console.log(socket.connected);// connected is showing true 
    });

    socket.on('messages', (data) => { // but here nothing happening. it is not coming inside function.
        console.log(data);
    });
}
请问这里有什么毛病。 非常感谢你的帮助
提前感谢

你确定这不是打字错误吗<代码>socket.on('messages')on('message')也许吧?您也可以发布发送这些消息的服务器端代码吗events@tarzenchugh,实际上,backed正在寻找其他人,但他正在为另外三个应用程序使用该代码后端代码,而在这些应用程序中,它就是working@Zee,我确信是
消息
您能看到控制台中是否有任何错误,可以使用
localStorage.debug='*'进行调试你确定这不是打字错误吗<代码>socket.on('messages')
on('message')也许吧?您也可以发布发送这些消息的服务器端代码吗events@tarzenchugh,实际上,backed正在寻找其他人,但他正在为另外三个应用程序使用该代码后端代码,而在这些应用程序中,它就是working@Zee,我确信是
消息
您能看到控制台中是否有任何错误,可以使用
localStorage.debug='*'进行调试