Good evening everyone, I need to implement a server, and so many clients can connect to it, how can I do this? I work with the Socket class, I did this but only 1 connection, 1 server = 1 client, and I would like 1 server = 100 clients (approximately)

    1 answer 1

    At what level did the question arise? In general, in the simplest case, you can create one serving thread per one incoming connection. For something heavily loaded, it makes sense to use BeginAccept / EndAccept method pairs in the stream that accepts incoming connections and BeginReceive / EndReceive in the serving thread.

    The general principle remains the same: after connecting the first client, continue to listen to incoming connections in parallel with the first one.

    • Just when I solved a similar problem on VB 6.0 there it was simpler, an array of sockets, and then it would be possible to address everyone by the array number, but in C # it’s somehow difficult. - Csharp
    • And what specifically prevents to move from a model with one client to a model with multiple clients? - eigenein
    • I do not know, I tried to do the same in C # Socket [] sck = new Socket [10]; And then refer to each element of the array, but he swears that the type does not specify an object reference. And what kind of model? - Csharp
    • one
      Of course, you need to initialize each element of the array just as you initially initialized a single socket. - eigenein
    • one
      Examples, generally speaking, a large number, for every taste and color. For example,… - eigenein