UDP how can two computers on separate networks connect to each other?
How can two computers that are on separate networks connect to each other using UDP? I know that you can do this by setting up port forwarding but I services like Xbox Live don't wor开发者_开发问答k through that. How is this possible and is there a way to obtain an address to another computer on a separate network?
EDIT
Ok thanks for the help I am using objc so I ended up using asyncsocket and portmapper for doing router configuration.
http://code.google.com/p/cocoaasyncsocket/
http://www.codingmonkeys.de/portmap/
First, obtaining the public IP of a remote computer:
- Use dynamic dns.
- Make your own protocol and run a server to keep the list of users and IP.
Working out incoming UDP packets:
- Use client/server communication instead of peer-to-peer.
- Use UPnP protocol (i think xbox does this) to ask your router for a port. Not all routers support or have UPnP enabled.
- Use TURN/STUN protocol. This protocol has been designed to bypass UDP nat. This requires an external server, but there are free servers available.
I think there are libraries for UPnP and STUN, but i can't tell you for sure.
LatinSuD are right, STUN is good solution - check out STUN protocol implementation for iOS https://github.com/soulfly/STUN-iOS
精彩评论