I'm trying socketio with webpack dev server using hmr. I'm not sure if it's related to my problem.
This is the most simple example I use:
Server side:
this.io.on('connection', function(socket){
console.log('a user connected');
});
Client side (inside a react component):
componentDidMount() {
var socket = io();
}
The problem when I do that it's "a user connected" appears a lot on the server side like if io() function is constantly called. It's spamming io connection.
Any idea where does this come from ? related to hmr or webpack ?
Edit: I've try to initialize socketIO own server Server side:
var server = app.listen(process.env.PORT || 3000 , function() {
var host = server.address().address;
var port = server.address().port;
console.log('App listening at http://%s:%s', host, port);
});
var ioServer = http.listen(process.env.PORT || 9090 , function() {
var host = ioServer.address().address;
var port = ioServer.address().port;
console.log('IO listening at http://%s:%s', host, port);
});
Client side:
var socket = io.connect('http://127.0.0.1:9090');
But it's the same result "a user connected" heavy spam. Hundreds of connection to io.