I have a web application using socket.io. It runs on localhost:8000 on my local machine. In order to find an annoying resource leak in my application, I tried to log out the connection events on my HTTP server:
server.on('connection', function(conn) {
//log out connection details
});
When I open the page inside my browser after the page loads, I can see multiple connection events in the log - something like these:
connection established: 127.0.0.1:54148
connection established: 127.0.0.1:54149
connection established: 127.0.0.1:54146
connection established: 127.0.0.1:54152
connection established: 127.0.0.1:54144
connection established: 127.0.0.1:54155
The strange thing is that I don't create a WebSocket connection after page load - only if the user clicks on a button. But I haven't clicked on any button and I still see these strange connections.
If I click on my button to connect with socket.io to my server, the log shows a new connection:
connection established: 127.0.0.1:54155
Fortunately every connections which I saw in the log were closed after some time - so I guess it couldn't be the reason of my resource leak.
But I'm still curious: what causes these connection events? And why is the port number so strange (not 8000 on which my server listens)?
Edit:
My server config is not a special one. In server.js
:
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var configSettings = require('./configSettings');
var socketIOServer = require('./server/socketServer')(io); // config socketServer
require('./server/static.js')(app, express); // static middleware
require('./server/routes.js')(app, configSettings); // routes
exports = module.exports = server;
exports.use = function() {
app.use.apply(app, arguments);
};
exports.configSettings = configSettings;
In start.js
:
var server = require('./server');
var port = server.configSettings.serverPort;
var serverIpAddress = server.configSettings.serverIpAddress;
server.listen(port, serverIpAddress);