In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to use TCP protocol to obtain server time in Ubuntu. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
The code is as follows:
# include "unp.h"
Int main (int argc, char * * argv)
{
Int sockfd, n
Char recvline [MAXLINE + 1]
Struct sockaddr_in servaddr
If (argc! = 2)
Err_quit ("usage: a.out")
If ((sockfd = socket (AF_INET, SOCK_STREAM, 0))
< 0) err_sys("socket error"); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(13); /* daytime server */ if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) 0) { recvline[n] = 0; /* null terminate */ if (fputs(recvline, stdout) == EOF) err_sys("fputs error"); } if (n < 0) err_sys("read error"); exit(0); } 然后我们运行这个程序若干次,每次以不同的IP地址作为命令行参数. 首先我们测试本机的时间,你必须要先打开Linux下的daytime服务,方法如下 代码如下: sudo apt-get install xinetd sudo vi /etc/xinetd.d/daytime 找到这一行,然后把yes改成no 代码如下: (disable = yes) ->(disable = no) sudo / etc/init.d/xinetd restart
Test this machine
The code is as follows:
Root@ubuntu:/home/jiang/UNP_STUDY/unpv13e/intro#. / daytimetcpcli 127.0.0.1
The result is:
24 OCT 2014 00:39:36 CST
To test the daytime of a server on the Internet, you must first find a server that supports the return of time using the TCP protocol. Some possible hosts were tested and found that some could be returned, some timed out or access denied.
The list of possible hosts is as follows, which is the list of time synchronization in the lower right corner of windows.
The dig directive is used here to resolve the domain name
The code is as follows:
Dig time.windows.com + short
Time.microsoft.akadns.net.
64.4.10.33
Run the program to try to get the time
. / daytimetcpcli 64.4.10.33
For the first time
The code is as follows:
Connect error: Connection timed out
The second time
The code is as follows:
Connect error: Connection refused
Change to another server
[code] dig time.nist.gov
. / daytimetcpcli 128.138.141.172 [code]
Result
56953 14-10-23 16:46:39 11 000 0.0 UTC (NIST) *
You can see visually that the local time is 4 o'clock in the afternoon.
This is how to use TCP protocol to get server time in Ubuntu shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.