I ask you to give an example of code for the simultaneous receiving and sending data through two network interfaces using TcpClient .

Motivation: I need to balance requests across multiple network interfaces. For WebClient there is an option ServicePoint.BindIPEndPointDelegate . TcpClient , but I did not find a similar option for TcpClient .

  • one
    Perhaps the motivation of the question is to move from the comment to the question itself. - VladD
  • one
    @Align: To do this, there is a "rediscover" button. Voted for rediscovery. - VladD
  • one
    @VladD, unfortunately my reputation does not allow this, so I would follow your example. - Align
  • one
    @Align: I'll quit chatting, I hope there will be people willing to rediscover the question. In addition, I made a clarifying revision, so the question will be in the queue for rediscovery. - VladD
  • one
    @Align: Here, rediscovered! - VladD

1 answer 1

It seems to me that the TcpClient constructor with IPEndPoint will suit you.

From the example in the documentation:

 var ips = Dns.GetHostEntry(Dns.GetHostName()).AddressList; var localEndPoints = ips.Select(ip => new IPEndPoint(ip, port: 0)); // как-то отфильтровать список var tcpClients = localEndPoints.Select(endPoint => new TcpClient(endPoint)).ToList(); 

How to find which interfaces belong to the external connection is discussed here . (Well, or you can try to connect to google.com for a test, probably.)

  • Is there a solution for HttpClient? to work simultaneously through 2 interfaces? - vitidev
  • @vitidev: For HttpClient not found. - VladD
  • @VladD, thank you, the variant is working, just checked. Who is interested, I can put an example for verification, but I think people here can write all this themselves. - Alexis
  • 2
    @Alexis: Please! Glad it helped! - VladD