简体   繁体   中英

How can two different hosts with different public IP can communicate through sockets? [C programming]

I'm trying to make a communication between two different hosts (using two different computers in my University). I saw that we only can bind to the socket local IP addresses . So how can I make a communication client/server just by knowing the ip public addresses of the two hosts?

PS: I can't have access to the local ip address of the computer of my university. Maybe for security reasons... And a ping between the two hosts with their public ip works properly.

You can not connect to the other host without tweaking the router.

[Host A Client] -- [Router A] -- (Internet) -- [Router B] -- [Host B Server]

Router B needs to know how to forward incoming packets to Host B , it's done by one of the following:

  • Demilitarized Zone
  • Static port forwarding
  • Dynamic port forwarding
  • Universal Plug & Play (NAT-PMP)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM