Note that there are some explanatory texts on larger screens.

plurals
  1. POChat server with a lot of clients
    primarykey
    data
    text
    <p>I read some C# chat source code &amp; I see that: on chat server with a lot of connected clients, server listener will run in a separated thread &amp; each connected client will also run in a separated thread. Code examples:</p> <p>Start server &amp; begin listening in a separated thread:</p> <pre><code> public void StartListening() { // Get the IP of the first network device, however this can prove unreliable on certain configurations IPAddress ipaLocal = ipAddress; // Create the TCP listener object using the IP of the server and the specified port tlsClient = new TcpListener(1986); // Start the TCP listener and listen for connections tlsClient.Start(); // The while loop will check for true in this before checking for connections ServRunning = true; // Start the new tread that hosts the listener thrListener = new Thread(KeepListening); thrListener.Start(); } private void KeepListening() { // While the server is running while (ServRunning == true) { // Accept a pending connection tcpClient = tlsClient.AcceptTcpClient(); // Create a new instance of Connection Connection newConnection = new Connection(tcpClient); } } </code></pre> <p>And a connection will also run in a separated thread:</p> <pre><code>public Connection(TcpClient tcpCon) { tcpClient = tcpCon; // The thread that accepts the client and awaits messages thrSender = new Thread(AcceptClient); // The thread calls the AcceptClient() method thrSender.Start(); } </code></pre> <p>So, if a chat server with 10000 connected clients, the chat server application will have 10002 threads (one main thread, one server thread &amp; 10000 client threads). I think the chat server will be overhead with a big number of threads. Please help me a solution. Thanks.</p> <p><strong>UPDATE:</strong> I believe chat examples are only for learning networking &amp; they are not suitable in real-world model. Please give me a real-world solution. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload