Introduction to TCP/IP (Part 3) - Client Server Model
Client Server Model Defined
The client-server programming model is a distributed computing architecture that segregates information users (clients) from information providers (servers).
- A client is an application that needs something like a web page or IP address from a server. Clients may contact a server for this information at any time. Clients are information users.
- A server is an application that provides information or resources to clients. It needs to be always up and running, waiting for requests from clients.
Client applications communicate only with server applications and vice versa. Clients do not communicate directly with other clients.
Client Server Examples
Example: DHCP Client Server
Here is a very common example of the client-server programming model. The dynamic host configuration protocol (DHCP) is the application responsible for requesting and offering IP addresses.
A DHCP client automatically requests an IP address from a DHCP server when a network is detected. A DHCP client could request a new IP address at any time, so the DHCP server must always be active and ready to respond to client requests. The DHCP server application typically exists in a router, but may also be found running on a network server for larger networks.
Example: HTTP Client and Server
I can use an HTTP client running on a PC to control the lights at home. This example shows an HTTP client running on a home lighting control board, which has been configured to monitor a lighting control website running on an Internet web server to determine if lights should be on or off.
I browse to the same lighting control webpage being monitored by the lighting control board, enter my username and password, and now have the ability to change the webpage. The next time the control board checks this webpage it will see the change and control the lights appropriately.
Example: HTTP Client and Server in the Same Local Host
A network host is usually either a client or a server but it is possible for a host to be both. Let’s see an example of this.
My control board may also have an HTTP Server running concurrently with the client. This could be used to serve a simple setup and configuration web page, which would allow me to change the website and log-in information the HTTP client uses to check for lighting control updates.
Example: Local Network HTTP Server
If you do have an HTTP server running on your embedded device, it could also be used to actually control the device.
This would allow you to eliminate the HTTP client application and Internet web server. At first, this may appear to be the best solution but looks can be deceiving.
This is probably the easiest solution if the HTTP client is running on the same local network as the lighting control board. Unfortunately, this is not very common.
The ability to control the lights or anything else from a remote location over the internet is a more likely and useful scenario. Accessing a web server on a local network from the Internet can be done, but it’s not a trivial task. Deciding where to locate a web server must be carefully considered.
Internet Server vs. Local Network Server
Internet Server
Accessing an HTTP server on the Internet is effortless. You are doing so now as you read this webpage. You may need to enter a username or password for some sites, but it really couldn't be easier.
In this example, the webpage that controls and displays the current state of the board runs on an HTTP server in the Internet. The embedded HTTP client posts its current status to the server and polls for new commands.
A web browser on a PC or smartphone can monitor and control the embedded device via the webpage in the HTTP server. The server may be implemented on a shared web hosting service from a company like GoDaddy™ or Network Solutions®, or may be implemented in the cloud, which is a service of decentralized servers from companies like Amazon Web Services (AWS), and Microsoft® Azure®.
These service providers will allow you to choose a website name so your webpage can be easily accessed.
Local Network Server
Instead of locating our HTTP server on the Internet, we could instead locate it on a local network. In this case, the webpage that controls and monitors the embedded device is actually running on the embedded device.
Just as in the previous case, a web browser on a PC or smartphone can monitor and control the embedded device via the webpage running in the embedded HTTP server.
Servers on local networks have some challenges that internet servers do not have.
Local Network Server Obstacles and Solutions
Local Network Server Obstacles
Locating a Hypertext Transfer Protocol (HTTP) server on a local network has some challenges.
The firewall in the local router restricts public access to the local network. You will need to allow remote HTTP clients on your local network.
A remote HTTP client will be able to access your webpage using the local network IP address, but you will probably want to provide a website name for convenience.
Also, your local network may not have a static IP address. If your internet service provider changes the IP address to your local network (if you have a dynamic IP address), how will a remote HTTP client access your webpage?
Solutions: Port Forwarding
Generally speaking, we want to prevent public Internet traffic from accessing our private local network. Nevertheless, you can allow Internet hosts to access your local network through a mechanism in the router called port forwarding.
Port forwarding allows Internet packets destined for a particular port on your local network to be forwarded to a specific local network IP address. Care must be used when allowing this access.
For our application, we need to configure the local router to forward incoming HTTP server packets to the local IP address assigned to the host running the HTTP server. Unauthorized access to the webpage can be prevented by requiring a username and password. You should also use some kind of encryption like SSL to prevent a packet sniffer from stealing your credentials.
Properly implemented and secure port forwarding is also referred to as a “firewall pinhole.”
Solutions: Local Server Website Name
Your web server is not required to have a website name, but it provides significant advantages.
Website names are easier to remember than IP addresses and if the IP address changes, DNS servers can be automatically updated to handle the change.
You can acquire domain names from domain name service companies like GoDaddy or DynDNS.
Solutions: Dynamic IP Address
Before we discuss how dynamic IP addresses affect the ability to access a local server, we first need to know what a dynamic IP address is.
Dynamic IP addresses are IP addresses that can change at any time. Internet service providers typically assign dynamic IP addresses to their customers. You can usually obtain a static IP address from an ISP, but they will charge you more for it.
Static IP addresses, as their name implies, are fixed and never change. Internet routers and servers typically use static IP addresses.
If your local router has been assigned a dynamic IP address, how does a remote host access your web server if the IP address changes?
If your remote HTTP client is using your website name instead of an IP address to access your HTTP server, all you need to do is update the DNS server with the new IP address. Some routers have this capability built into them. If yours doesn’t, you can have your embedded device periodically check its local network IP address and have it update its DNS server if it changes.
DynDNS and ZoneEdit are examples of two DNS service companies that can provide you with a domain name and the ability to update their DNS servers if your IP address changes.