开发者

Peer-to-peer behind the NATs using C#

开发者 https://www.devze.com 2023-03-20 09:48 出处:网络
I have a general question that was probably answered somewhere here, but using search was not very productive. So, I will reask and if there\'s a thread about that, please point me there. Thanks.

I have a general question that was probably answered somewhere here, but using search was not very productive. So, I will reask and if there's a thread about that, please point me there. Thanks.

So, the general idea is: We have two .NET-written clients that want to talk to each other without routing the whole traffic through the server. Even more, it is not necessary for both clients to be .NET based, but one will be in any case (another can be Objective-C, C++ on Unix etc.).

The idea is:

  1. The first client establishes the connection to some server so NAT remembers that the client is on address 10.0.0.1:1234 and the server is on address 70.0.0.7:4567. So, when the 70.0.0.7 will send the packet back to NAT, the NAT will know how to masquerade it to client.
  2. The second client establishes the connection to the same server so second NAT also remembers that the inter开发者_如何学Pythonnal client on address 192.168.0.1:19234 is connected to server on address 70.0.0.7:7654 and will also be able to accept packets back for 192.168.0.1:19234
  3. Now we need to make the connection from 10.0.0.1:1234 to 192.168.0.1:19234.

Both c# clients can know about endpoints of each other (let's say the server keeps the NATted addresses and they are: Client1 - 111.0.0.1:1111 and the Client2 - 222.0.0.2:2222). What is necessary is - for Client1 to be able to send the packets directly to 222.0.0.2:2222 without calling Socket.Connect fist and for Client2 send packets to 111.0.0.1:1111 without calling Socket.Connect as well.

Is that possible to do with a .NET only without using any special libraries just using standard sockets etc.?


Sounds like you want to do something similar to UDP hole punching


Or NAT traversal

0

精彩评论

暂无评论...
验证码 换一张
取 消