How do I connect 2 different subnet’ed computers? For example sake let’s say the following:
192.168.1.92 connected to externally visible 222.251.155.20.
192.168.1.102 connected to externally visible 223.251.156.23.
Now there is middle man server that both machines are connected to so they can negotiate each other’s internal and external IP’s and have one open up a listening port. The only way I currently know how to do this is port forwarding.
I’m fairly proficient with C# sockets, just don’t how to connect two computers that are on two different subnets.
I have a server that the clients connect to that has a domain name, usally the clients will be behind home routers and I want them to be able to share information directly with each other.
What you’re looking for is NAT traversal.
Solutions without a relaying server and without port forwarding usually use some form of UDP hole punching.
A standardized mechanism is STUN (i.e. Interactive Connectivity Establishment).
Note: implementing UDP hole punching and reliable file transfer over UDP is not trivial. The best option is probably to automatically set up port forwarding with UPnP or NAT-PMP. There are libraries for both, e.g., Mono.Nat (sources):