What does NTP client asks NTP server when it bumps into it ? Hey buddy, What's the time?
NTP protocol is used by computers and embedded devices to synchronize time to a common clock reference across the internet. Many embedded devices like a WLAN Access Point(AP) ,IPTV Set Top Box (STB), smart TV etc do not have hardware clock inside them. These devices heavily rely on NTP Server to get the correct time.
NTP based time is used for many critical processes inside these devices. For example a smart TV needs a correct time stamp for various things like:
- Logging : If we have to debug some issue, which user is facing, we need a correct time stamp to relate user specified problem with exact date and time inside the logs.
- Device Lease : When your device gets connected to an ethernet interface or to WiFi interface , it will have DHCP lease allocated , If your device does not have correct date and time, your DHCP lease could lie in past and DHCP client on your device can start to behave insanely and it can get abrupt disconnections.
The piece of software which runs on embedded devices to synchronize the time over the internet is called NTP client. NTP client talks to NTP server to get the correct date and time. NTP client uses UDP protocol for its operation and it operates over UDP port 123 at transport layer. Following sequence of packets exchange happens between NTP server and NTP client to update the time:
- NTP client sends the packet to NTP server containing its own time stamp
- NTP server responds this request with a packet containing 2 time stamps:
- The original client timestamp.
- the time at which server received the request from NTP client.
- the time at which server is sending the response to NTP client.
- Client estimates the delta between its timestamp and server timestamp.
- Client can talk to multiple NTP servers.
- But it will sync up with only one NTP server based on the offset and jitter.
On most of the embedded devices the default time zone is UTC. NTP server and NTP client exchange messages in UTC format. If after NTP synchronization , We want our device to display the correct date and time , then it should apply the correct timezone on UTC time.