0

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).

  1. 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)
    
  2. 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?

  3. 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?

Lorenzo
  • 111
  • 3
  • 10
  • You are mixing several questions into a single one ([1] and [2] are totally independent) which makes this question too broad. Please ask these as separate questions but make first sure that there are not already similar questions with answers. Apart from that from the perspective of programming exchanging data between different networks is no different from exchanging data inside the same network. It might be different though from a networking point (which has nothing to do with Python) if firewalls, NAT or similar are involved. – Steffen Ullrich Sep 15 '19 at 13:04

1 Answers1

0
  1. Your understanding of use cases for UDP and TCP seem roughly accurate. UDP ensure lower latency (not always) so for apps that require lowest latency possible while also not caring about missed packets, UDP is used. So if you think about video streaming, once a packet is missed, it makes no sense to hold up every future packet for that one old packet. This is because a small amount of data that is missed doesn't really affect a user's watching experience. For gaming, we want the newest data as soon as possible, so waiting for old data also doesn't matter. But if you're implementing a protocol or something that requires all data to be transmitted, TCP makes sense since its absolutely vital that all information gets to the receiver and in order.
  2. There are a few methods to exchange data between two private networks. Port forwarding is certainly one method, and both machines on either network would have to have port forwarding. I don't know anything about automated port forwarding like you mention, but you can go into your router settings and set it up pretty easily. Another method of talking across networks is something like webRTC. Its a protocol that uses the STUN TURN and ICE protocols to perform something called NAT traversal. Short story shorter, it tricks your routers into letting your machines talk to each other(analogous to temporary port forwarding).
  3. You're right that this could be an issue. However you should be able to setup static IP addresses in your router. So you can assign one machine to have a static IP address, setup port forwarding, and bam you have a permanent(hopefully) open connection.
Mataan P
  • 117
  • 1
  • 8