为什么 SocketIO 多次连接到服务器?

时间:2021-02-26 12:52:41

标签: node.js reactjs socket.io

这是客户端的代码,

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 这是这段代码的仓库

编辑:

enter image description here

它每隔一段时间就会创建这个请求

0 个答案:

没有答案