这是客户端的代码,
const url = "localhost:8080"
const socket = socketIOClient(url);
socket.on("broadcast", (value) => {
this.props.getUpdate(value)
})
这是Server nodejs express上的代码,
io.on('connection', function(socket){
console.log('A user connected');
});
服务器上的console.log 每隔一段时间运行一次以上,不知道为什么?
注意:客户端与 redux 反应
编辑:
componentDidMount() {
const url = "localhost:8080"
const socket = socketIOClient(url);
socket.on("broadcast", (value) => {
this.props.getUpdate(value)
})
}
我只是在 componentDidMount 函数中创建了套接字。
https://github.com/Mrbiyik/platraFrontend 这是这段代码的仓库
编辑:
它每隔一段时间就会创建这个请求