i actually discovered this by accident while programing my live audio network. picture the scinario where 2 clients, each behind it's own NAT/Router want to send/recieve data between eachother. imagine both clients are listening for data on udp port 8000. assuming both clients know eachothers ip addresses and the ports they are listening on, simply opening port 8000 on each router is enough to let them both communicate. supprisingly enough most people dont know how to open ports on routers and this will almost deffinatly limmit the prospective user audience, not good if your hoping to make money from your new network application. when a client behind a nat sends data outside of its local network, the port number its sent on is decided by the nat and not the application that is sending for example, client 1 sends data to client 2 on port 8000, if client 2 is not behind a nat it should get the data no problem. now heres the interesting bit, client 2 recieves the data but for some reason it recieved the data from client 1's internet ip on port 62000. why? here's why http://www.brynosaurus.com/pub/net/p2pnat/ as long as client 2 knows what ip and port client 1 sent from, replying to this ip/port will work because thats what NAT's are supposed to do. If the nat on client 1's network recieves a message from the ip it sent to on port 62000, it accepts the packet. the next important bit is to make sure all the clients who want to communicat directly with eachother know eachothers external ip/NAT port. this is as simple as hosting a server that records clients ip/ports and passes them on to other clients on the network. obviously the server must not be behind a nat, but if it is, you can open the port its listening on, on the router. sorry im at work and trying to dodge the boss while i type this, the link will actually make sense as just reading this back to myself, im baffled. so to recap, if u send a packet to a client on port 8000, the recieving client cannot send back to your ip on the same port because your nat sent the message from a different port, as long as u know this port u can reply.
|