Python socket over DDNS

502 Views Asked by At

How can I host and connect to a socket server with a socket client in python?

No further questions or details, because I have no clue.

1

There are 1 best solutions below

1
ibrust On

Speaking not as an expert on DHCP or DDNS, but just someone with basic familiarity-

Let me first describe what your problem seems to be. You have a server... it has a specific IP address. And it has a domain name - let's say www.myDomain.com. DNS provides a mapping of that domain name to an associated IP address. That way when you type www.myDomain.com into your browser... a message is sent to your local DNS server asking "what IP does this name www.myDomain.com actually map to"? After that's resolved, your network request is sent to the actual server located at that IP.

With DHCP... your servers IP is not static. It changes - it changes frequently. Your IP has a certain lease window, after which it expires. The idea behind DHCP is the dynamic assignment of IP addresses - it allows devices to connect / disconnect to the network without manual configuration, and it also conserves IP addresses by reusing them. But because your servers IP is changing frequently, this means the DNS servers need to be updated with the new mapping from your domain name - www.myDomain.com - to that new IP address.

You have to update the DNS server so the client knows what IP address to send the request to. That's the socket part - clients & servers maintain a network connection between them. The socket is the application level interface for that network connection. The socket needs the correct IP address. It interfaces with DNS servers to resolve domain names IP addresses.

This is what DDNS is. DDNS is an extension to DNS to accommodate the DHCP protocol. The old DNS system was not sufficient for handling these frequent, dynamic IP updates from DHCP.

So you can start by reading up on what DDNS is. The wikipedia article is a good starting point. If you're really lost, then first learn what DHCP and DNS are.

The way DDNS works is a daemon that runs on your client polls for updates from the DHCP server and sends an update to your DNS server every time your IP changes due to DHCP updating it (DNS is usually implemented with the BIND software - it runs on the servers & clients). And that happens frequently. You would not write this yourself under any circumstances... You could configure your own server with BIND (a piece of server software) to handle this. You'll need to read BINDs documentation (beware configuring BIND can get pretty complicated). But really you'd just trust that the DNS systems out there supported DDNS (because they all do), and you'd use python's high-level requests library that I suspect already takes care of all this. If you're using some high level, up to date sockets library and you're still having issues... only then try to go deeper.

For a serious server application people generally purchase a static IP for their server from the ISP, and then the application won't experience any disruptions when the server updates its IP.

I think Amazon's IPs are static... you should be using a cloud server anyway, so read the documentation of your cloud service and figure out how their VMs typically handle IP addresses. My bet is the IP will just be static, if not you will be able to purchase one.