You need to look more at the architecture for creating such an environment. First of all, if you write socket management yourself, do not use Thread for Client Socket. Use asynchronous methods to receive and send data. WebSockets can be too heavy if your messages are small. Since it implements framing, which must be applied to each message for each socket individually (caching can be used for different versions of the WebSockets protocols), which makes them process both directions more slowly: for receiving and sending, especially due to data masking.
You can create millions of sockets, but only the most advanced technologies can do this. Erlang is capable of handling millions of connections and is quite scalable. If you want to have millions of connections using other higher-level technologies, you need to think about clustering what you are trying to accomplish.
For example, using a gateway server that will monitor all processing servers. And to have data from them (IP, ports, download (if it is one internal network, a firewall and port forwarding can be convenient here). Client software connects to this gateway server, the gateway server checks the least loaded server and sends the ip and port to the client The client creates a connection directly to the production server using the provided address, so you will have a gateway that can also handle authorization and will not bind connections for a long time, so one of them may be enough And many employees who publish data and store links.
This is very related to your needs and may not be suitable for your decisions.
source share