This is definitely the age of instant communications. Everyone expects you to be online and available almost all the time. Everyone has an online connection point that needs monitored and respected. Otherwise, you end up with unhappy customers and friends.
Have you wondered how these different types of notifications work and how can you do your own. In this tutorial, I will introduce you to the amazing world of notifications and how you can do it yourself.
This tutorial is in two parts and will teach:
- the theory and methods behind active notifications
- the theory in a real web server example
The Theory and Methods Behind Active Notifications
In this, the first part of the the tutorial, I'll show you the theory and methods behind active notifications.
Types of Notifications
Not all notifications are the same. For instance, if you have a program that tells you about a new Facebook notification, you have a polling program that will poll the Facebook server periodically to see if you have anything new.
If you have Dropbox on a server with a program that makes use of web-hooks, then you have a direct notification system to notify the server of a change in the Dropbox file system.
Polling systems are the easiest to setup, but require more complicated code on the server to store notifications. It’s up to the user’s computer to run a program that will periodically query the web server. That, however, means the frequency of polling determines the notification latency. Therefore, if the polling program checks once an hour, the worst case contact delay will be one hour. If the polling frequency is too quick, you'll bog down the system. Especially if you have many such programs.
Direct systems tell the server how to contact you once a network connection has been established. When a notification comes, the server will contact the computer directly. No wasted time in polling, but contacting the system can be problematic. Direct notifications are difficult to maintain due to protective gear on the internet.
In this tutorial, I'll show you the Direct or Active notification options. I will also show you the possible problems and how to get around them.
Method of Making Contact
Every computer that is on the Internet has a unique identification number called an IP address. In order for one computer to connect to another, it has to obtain it’s IP address. Typically, you would use a Domain Name Server (DNS) to obtain the IP address from a unique server name.
For example, to contact my website, my computer contacts the DNS Server to translate customct.com to it’s IP address of 184.108.40.206. My computer received the IP address of the DNS Server when it connects to the Internet Service Provider or ISP. The DNS Server knows the IP address of the computer requesting information from the request. The DNS Server then returns the IP of the webserver matching the name.
Upon setting up a web server on the Internet, they receive a unique static IP address that will not change for most of the life of the server. The web browser on my computer contacts that IP address for the contents of my website. This is how a computer can directly contact to another computer on the internet.
The problem with this method of contacting is that not every computer on the Internet has a name associated with it. Your home computer only has an IP address, and not a name that any DNS Server would know about.
To make matters even harder, every time a computer connects and disconnects from the internet, it is dynamically assigned an IP address. Each ISP has a group or pool of IP addresses it can give out to it’s customers, but the customer only uses that IP while connected. The next time you connect, your computer will most likely get a different IP address.
Dynamic DNS Servers
One way for a server to know how to contact a computer is to subscribe to a Dynamic DNS service or DDNS. Typically, you get a name that is a subdomain of their DNS name.
Whenever a user needs the IP address of the computer, they will contact the DDNS service for your current IP. You then run a program on your computer that updates the DDNS service periodically or whenever the IP changes.
One such service is Dynu Systems. When you register with their service, they give you a free DNS name for your computer that is a subdomain of their main domain name. For example, I created an account for customct on Dynu Systems’ free DNS.
The name for my computer is customct.freeddns.org. On the command line, I can type:
to receive the output of:
Server: 220.127.116.11 Address: 18.104.22.168#53 Non-authoritative answer: Name: customct.freeddns.org Address: 22.214.171.124
The nslookup command is a command line program for performing a DNS lookup on a name to get the IP address associated with the name. In this example, nslookup queried the DNS server at 126.96.36.199, which is the Google Public DNS. The Google Public DNS then queried the DDNS provider. The DDNS provider gave the address of 188.8.131.52, which was the last given valid IP for that system.
Problems Contacting a Home System
Now, the first attempt I conducted to contact my home system from a server, it just sat there without my system ever getting a notification. By using traceroute, a command line utility on Linux and Mac systems, on the server, I found that the notice stopped at the local router in my home.
My Internet Service Provider supplies a masquerading router, in my house, that disguises all the computers in my house with a different IP address. Once I received the login credentials for the router, I was able to fix the problem.
You will have to open the router’s administration screen in the web browser to the setup for a DMZ zone. DMZ stands for DeMilitarized Zone: a military term meaning that the area or zone is not protected. You set the computer’s Local IP address to the Destination: IP Address.
Since every home router is different, I can’t possibly show every possible configuration. Above, I'm showing a Linksys E1200 router set to place the computer at the local IP address of 192.168.1.111 in the DMZ zone. That computer will now receive all traffic directed to the router that isn’t handled by any other routes.
Be very careful as that computer isn’t protected from hackers on the internet.
I setup the router to always give my computer the same IP address. That way, my system is always in the DMZ zone. Once my computer was in the DMZ zone, the notifications came through fine.
You'll have to get the login information for the local router from your ISP or from the instruction manual for the router if you setup the system yourself.
If the system to receive notifications is on a cellular network or public Wi-Fi, it might not work as well. Many cell phone networks and all public Wi-Fi networks do not allow systems to receive information originating from the internet. In that case, this type of notification system will never work and you will have to store the notifications on the server and download them periodically to your local computer.
Now that you understand how notifications work and the potential problems, I will show you how to apply this theory to a real system. I will show how to create a Node.js server that will notify a home computer by using a DDNS service and a direct connection. The server will contact Keyboard Maestro's public macro execution server to respond to the request.
Subscribe below and we’ll send you a weekly email summary of all new Computer Skills tutorials. Never miss out on learning about the next big thing.Update me weekly
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post