Communication between client and server when DHCP is enabled

I have an embedded device which runs Linux and acts as a client, and a server at office. The IP address of the client is allocated by DHCP, so its IP address is actually

variable. I would like to know what is the simpliest way to maintain the communication between client and server when DHCP is enabled.

I once used socket many years ago to communicate between the client and the server. If I remember it right, I actually bypassed the dynamic IP issues by

using the computer name to replace the IP address. Even the client is not at the same local network as the server, the scheme still worked. Correct me if my

memory cheated me. Please let me know if socket is still the best solution for this kind of application involving DHCP?

I also heard from someone that it is necessary to implement multicast discovery protocols named BONJOUR, but I don't think it is necessary, and I don't think

it is a simple solution. What do you think?

Thanks.

Reply to
like2learn
Loading thread data ...

Typically the DHCP assigned IP address doesn't change for during a session, if it does, things tend to break.

Anyway, it's usually a very bad idea to use IP addresses directly. They change. Usually you refer to DNS names ("

formatting link
" and not "1.2.3.4"), and you use an API like GetHostByName() to translate that to an IP address that you use in a Connect(). Some networks provide non-DNS name resolutions, but those certainly don't generally work over the Internet (for example, Windows will resolve the machine name within a domain).

A server's IP is usually fixed, so static DNS works. And in most cases it's the client connecting to the server, so it's only the client that needs to look up the server's IP address anyway. Dynamic DNS is commonly used when you don't have a static IP address, and you still need to handle inbound connections. The basic scheme is that you have a DDNS server someplace, and whenever the machine in question is a leased an IP address by DHCP, it reports that to the DDNS server, which then serves it via the usual DNS mechanisms. You can set some of that up yourself, or pay a DDNS vendor a few bucks to do it.

Reply to
robertwessel2

You really don't understand this application - whatever it is - well enough to implement it, based on the questions you're asking. Homework assignment?

A device of this sort is almost certainly NOT on the Internet with a real IP address; it is sitting behind a router that is most likely doing NAT. So it doesn't have an IP address reachable from the outside world. There are ways around this, but the most common way of doing it is by opening an OUTBOUND socket from the node to home base, and then sending heartbeat traffic through periodically. This won't require any configuration change on the router beyond possibly opening a port (perhaps not even that, if you use a well-known port that is probably open for outbound connections already, e.g. 80).

Reply to
larwe

To open an OUTBOUND socket from the node to home base, do I need to know the Domain Name of the server in advance? Do I need a name server in place? I think most enterprise already have a name server in place. Thanks!

Reply to
like2learn

a

Yes, although for small organizations it's almost always hosted externally, often by the ISP. Or any of dozens of DNS providers.

Reply to
robertwessel2

The free service offered by dyndns.org is a possibility here.

Mel.

Reply to
Mel

d a

,
n
k
e
t
y

quoted text -

Thanks!

Reply to
like2learn

Assuming the client *originates* the connection, you have nothing to do. It connects to the server at a well-known name/address/port. Server sees an incoming connection on that port and completes the open().

If, OTOH, the server wants to originate the connection (!???), let the client register it's IP with a dynamic DNS using a well-known name and have the server resolve that name before it tries to connect.

Reply to
D Yuniskis

On linux you just have to install avahi, it's the linux implementation of the zeroconf/bonjour protocol.

Bye Jack

Reply to
Jack

Do I really need to install avahi on linux considering most router manufacturers already supported dynDNS in their equipments? BTW, to install avahi is just a simply download-and-run process, or the user is required to configure or modify the settings to make it work? Thanks.

Reply to
like2learn

Zeroconf is not the proper solution here. It is a local link protocol which does not work over routers.

--

Tauno Voipio
Reply to
Tauno Voipio

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.