Filip Egeric
Filip Egeric

Reputation: 113

More than 256 concurent websocket connections in Node.js

Is it possible to have more than 256 connections in Node.js using websocket library? I have this code on server:

const WebSocket = require("ws");
const clients = [];

const wss = new WebSocket.Server({ port: 8080 });

wss.on("connection", function connection(ws) {
  clients.push(ws);
  console.log("number of connections: " + clients.length);
});

And when I try this in the browser:

let i = setInterval(() => new WebSocket("ws://localhost:8080"), 100);

it gets to 256 clients(concurrent connections) and then it stops? What is causing this and is it possible to go beyond this number and how much beyond?

Upvotes: 0

Views: 712

Answers (1)

erwan
erwan

Reputation: 421

It is not a Node.Js limit. It is a Chrome and more specifically Chromium limit.

See in the source code: https://github.com/chromium/chromium/blob/476d57d846b1a97c7c25089ccbb0f576803a9ca2/net/socket/client_socket_pool_manager.cc#L30

To go beyond you should not use a browser, Firefox has the same limit. Or you can use multiple browsers at the same time but it depends on the number of concurrent connexions you need?

Upvotes: 1

Related Questions