【发布时间】:2019-04-13 14:37:36
【问题描述】:
我有一个 expressjs 服务器代码,它监听如下所示的套接字端口。
websocket.on('connection', (socket) => {
console.log('A client just joined on', socket.id);
websocket.on('messageIM', (message) => {
console.log('msg:'+message)
});
});
我的客户端应用程序是一个 react-native 移动项目,其中包含如下代码:
constructor(props) {
super(props);
this.socket = SocketIOClient('http://192.168.140.51:3000/');
}
我在服务器控制台上得到客户端连接'A client just join on ***' log,表示与服务器的连接成功。但是当我发出一些变量时......服务器端不会发生任何事情!......
call()=>{
this.socket.emit('messageIM','Hi server')
}
意味着当我调用上面的 call() 函数时,服务器没有任何反应。
这是我在客户端和服务器端编写的代码,如果您有这方面的经验,请提供一些帮助。
【问题讨论】:
标签: node.js reactjs react-native websocket socket.io