1 Star 0 Fork 0

20191205/zx代码

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
echo.c 791 Bytes
Copy Edit Raw Blame History
20191205 authored 2021-12-20 11:38 +08:00 . add echo.c.
#include "csapp.h"
#include <time.h>
void echo(int connfd, char *haddrp)
{
time_t t;
struct tm * lt;
size_t n;
char buf[MAXLINE];
rio_t rio;
Rio_readinitb(&rio, connfd);
while((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0) { //line:netp:echo:eof
//printf("server received %d bytes\n", n);
printf("\n客户端IP:%s\n",haddrp);
printf("服务器实现者学号:20165330\n");
time (&t);//获取Unix时间戳
lt = localtime (&t);//转为时间结构
printf ("当前时间为:%d/%d/%d %d:%d:%d\n",lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec);//输出结果。注意月份取值区间为[0,11],所以要+1;年份的修改。
Rio_writen(connfd, buf, n);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/two_thousand_and_thirteen/zx-code.git
git@gitee.com:two_thousand_and_thirteen/zx-code.git
two_thousand_and_thirteen
zx-code
zx代码
master

Search