title: How to manage large number of TCP connections using ASP.NET and C#
body: <p>I have an application which connects to a third party server let’s call it Server-A. I have been given four different ports i.e.
  4000, 40001, 40002, 40003. On each port I can create 20 connections so I can create 80 total connections with server-A. I want to create a service layer that should communicate with server-A on mentioned ports. The technology will be asp.net C#. </p>
  
  <p><strong>The problem statement</strong></p>
  
  <p>1- Application should be non-blocking/asynchronous to entertain 10 to 20 million request per day</p>
  
  <p>2- Whenever the service layer starts it create 20 connections on each port. (Total 80 connections)</p>
  
  <p>2- All connections should remain connected/alive 24/7 and reconnect whenever any connections drops/disconnects. It will send a heartbeat message in idle time. </p>
  
  <p><strong>My Questions</strong></p>
  
  <ul>
  <li>How can I manage these connection? Should I add those to a static list one by one when a TCP socket is successful?</li>
  <li>How can I know that a certain connection is dropped/disconnected? </li>
  <li>How can I send certain requests on different ports? Let’s say if a>b send it on port 4000 else if a&lt;=b send it on 4001</li>
  <li>How can I make it asynchronous?  </li>
  </ul>
  
  <p>For an initial start I created a single TCP connection on single port and it works as expected. Then I replicated the same code for other port, but I know it is very bad approach and I have to copy same code 80 times to make 80 connections. I want a clean and scalable way to achieve it, so that in future may be I increase the connection to 100 or more. 
  Is there any framework which I can use?
  Any help would be greatly appraised. </p>