作者Magic_code,转载请附上!
功能:服务器提供时间服务,客户请求时间信息并显示结果
流程如图:
头文件unp.h
1 #ifndef _UNP_H_
2 #define _UNP_H_
3 /* unp.h */
4 #ifdef cplusplus
5 extern "C"{
6 #endif
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h> /* for struct sockaddr */
10 #include <string.h> /* for strlen() and snprintf() */
11 #include <stdio.h> /* for printf() */
12 #include <unistd.h> /* for read() */
13 #include <arpa/inet.h> /* for inet_pton() */
14 #include <stdlib.h> /* for exit() */
15 #define MAXLINE 5