Monday 10 April 2017

node js net liblary - get info about the client(socket)

I use nodejs cluster with socket.io, and in the master thread i use the built in net library to listen on port and pass the connection(socket) manually to the workers (based on the client's ip address, so if the client reconnect to the server the client will join to the same worker). This is work well, but i would like to test, and i want to join to different worker from localhost.

Is there any way to get info about the client e.g.(browser name, custom parameter) or anything else to make different between two or more client from localhist? - It could be cool if i'm be able to join the client to a worker based on the browser (chrome clients goes to worker 1, firefox clients goes to worker 2) on development environment.

private createServer(): void {
    var self = this;

    this.masterServer = net.createServer(<any>{ pauseOnConnect: true }, (connection) => {
        console.log('server', connection);

        let worker = self.workers[self.getWorkerIndex(connection.remoteAddress, self.workerCount)];
        worker.send('privateCon', connection);

    }).listen(self.serverPort);
}



via Twois

No comments:

Post a Comment