I investigated a lot about this topic but most of the guides just teach how to exchange data between devices on the same network and, regarding exchanging data between devices on different networks, no source was totally clear to me. I hope with this question somebody can give me (and other users) a good overview. If you have any guide or book about it I’d be super interested (for Java would also be fine).
First of all I’m interested in the difference between programs that need to exchange data quickly (it may be an online videogame) versus programs that need to exchange data accurately (it may be a message app). My understanding is that the difference between the two is the protocol used: in the first case is UDP (where no checks are done to ensure there is no packets loss), in the second case is TCP (where checks are done and data is exchanged more slowly). Is this correct? So in an hypothetical Python script in the first case the socket created would look like this:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
While in the second case would look like this:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
My understanding is that to exchange data between different networks you have to use port forwarding (very good explanation here), concept that is clear to me. However, do you have any source that suggests how to do it in Python? Also, is port forwarding everything you need to do in order to exchange data between different networks? Finally, I’m not sure I understand the role UPnP plays in port forwarding. Based on this question it seems UPnP is a way to automatically port forwarding. Is it correct? Can I use miniupnpc library to do it automatically?
Finally, if I switch off and on my router, the private IP addresses assigned to the devices connected to the network change (so the private IP of my phone connected to my home WiFi could change, for example, from 192.168.1.2 to 192.168.1.11). Does this represent a problem in networking programming? If I set on the router a certain port and the traffic that comes to that port is directed to a certain private IP address and then this IP changes I suppose there is a problem. Is this correct? If it is what is the solution?