2

I have just learned that you can use a Thread pool for multi client TCP-connections, I have an C# application today that I like to implement this to. I have read some, for example the first answer to this question ( Best way to accept multiple tcp clients? ), but I dont really get how to make the last adjustments to work with my "needs". I have a messagehandeling function for each connection (each connection is 2 threads, one for recieving/sending messages (connection open for a long duration moste of the time) and one for doing Tasks depending on the messages (also creates answers to send back). I would now like to use the recieving method in the link below, but how can I do this with a thread pool in my example?

If anything is unclear, just ask questions!

/Nick

Community
  • 1
  • 1
Nick3
  • 639
  • 1
  • 14
  • 40
  • 1
    [How To Use the SocketAsyncEventArgs Class](http://www.codeproject.com/Articles/22918/How-To-Use-the-SocketAsyncEventArgs-Class) – L.B Sep 02 '12 at 18:52
  • Thanks! But I dont really think this handles my example. How do I do the specific part of doing Tasks depending on the messages (also creates answers to send back). For example I would like to when I get a specific message, send an answer (new message) to an other of the clients, how can I keep track of the sockets/clients? For example: Client 1 says: send this msg to Client 2, how can I know what socket is what client? – Nick3 Sep 02 '12 at 19:39
  • I posted it not to use as is. It shows how to use async operations. – L.B Sep 02 '12 at 19:56

1 Answers1

0

Just avoid having one thread per connection. It generate lot of overhead on the OS and doesn't scale well.

Today we use NIO : non blocking I/O. One thread can handle 10k+ connections. There are very easy way to use them, like NodeJs for example. NIO libraries are available for most platform/languages (Netty for Java, NodeJs with javascript,...).

You should specify wich language/environement you are using.

bokan
  • 3,601
  • 2
  • 23
  • 38
  • Just search for it ! I found this using a popular search engine. http://stackoverflow.com/questions/648282/any-nio-frameworks-for-net search also for article about the 10k problem – bokan Sep 02 '12 at 18:47