往期文章推荐:
epoll() 多路复用 和 两种工作模式_呵呵哒( ̄▽ ̄)"的博客-CSDN博客https://blog.csdn.net/weixin_41987016/article/details/132523789?spm=1001.2014.3001.5501
epoll_server.c
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <errno.h>
// server
int main(int argc,const char* argv[]) {
// 创建监听的套接字
int lfd = socket(AF_INET,SOCK_STREAM,0);
if(lfd == -1) {
perror("socket");
close(lfd);
exit(1);
}
// 绑定
struct sockaddr_in saddr;
memset(&saddr,0,sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(9999);
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
// inet_pton(AF_INET,"127.0.0.1",&saddr.sin_addr.s_addr);
// 设置端口复用
int optval = 1;
setsockopt(lfd,SOL_SOCKET,SO_REUSEPORT,&optval,sizeof(optval));
// setsockopt(lfd,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));
// 绑定端口
int ret = bind(lfd,(struct sockaddr*)&saddr,sizeof(saddr));
if(ret == -1) {
perror("bind");
close(lfd);
exit(1);
}
// 监听
ret = listen(lfd,64);
if(ret == -1) {
perror("listen");
close(lfd);
exit(1);
}
// 创建epoll 实例
int epfd = epoll_create(1);
if(epfd == -1) {
perror("epoll_create");
close(lfd);
exit(-1);
}
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = lfd;
// 创建了epfd,设置lfd上需要检测事件并将lfd绑定到epfd
ret = epoll_ctl(epfd,EPOLL_CTL_ADD,lfd,&ev);
// epoll_ctl 调用成功返回0,调用失败返回-1,可以通过 errno 错误码获取具体的错误原因
if(ret == -1) {
perror("epoll_ctl");
close(lfd);
exit(1);
}
struct epoll_event evs[1024];
int size = sizeof(evs)/sizeof(evs[0]);
while (1) {
// epoll_wait 检测事件
int num = epoll_wait(epfd,evs,size,-1);
if(num < 0) {
// 被信号中断
if(errno == EINTR)
continue;
// 出错,退出
break;
} else if(num == 0) {
// 超时,继续
continue;
}
printf("num = %d\n",num);
for(int i = 0;i < num;i++) {
// 判断是否是监听套接字
int curfd = evs[i].data.fd;
// 如果是监听套接字,则处理连接请求
if(curfd == lfd) {
struct sockaddr_in caddr;
socklen_t len = sizeof(caddr);
int cfd = accept(lfd,(struct sockaddr*)&caddr,&len);
if(cfd == -1) {
perror("accept");
exit(1);
}
// 注意:传递给epoll_ctl之后,会做一个拷贝,其实可以不用再创建一个epoll_event ev
ev.events = EPOLLIN;
ev.data.fd = cfd;
ret = epoll_ctl(epfd,EPOLL_CTL_ADD,cfd,&ev);
if(ret != -1) {
printf("new cfd: %d add to epoll success",cfd);
} else {
perror("epoll_ctl");
close(cfd);
}
printf("accept a new client: %s:%d\n",inet_ntoa(caddr.sin_addr),ntohs(caddr.sin_port));
}
else {
// 如果是连接套接字,则处理读写事件
char buf[1024];
int len = recv(curfd,buf,sizeof(buf),0);
if(len == -1) {
perror("recv error");
// 出错,从epfd上移除cfd
if(errno!=EWOULDBLOCK && errno!=EINTR) {
ret = epoll_ctl(epfd,EPOLL_CTL_DEL,curfd,NULL);
if(ret == -1) {
printf("client disconnected,cfd: %d remove from epoll error \n",curfd);
}
close(curfd);
}
} else if(len == 0) {
printf("客户端已经断开连接...\n");
// 先删除
ret = epoll_ctl(epfd,EPOLL_CTL_DEL,curfd,NULL);
if(ret != -1) {
printf("curfd: %d delete from epoll success\n",curfd);
}else{
perror("epoll_ctl");
}
// 再关闭
/*
注意:如果咱先关闭这个通信的文件描述符,然后再对这个节点进行删除
这个epoll_ctl会返回-1,也就说删除失败
*/
close(curfd);
}
printf("read buf = %s\n",buf);
// 小写转大写
for(int i=0;i<len;i++) {
buf[i] = toupper(buf[i]);
}
printf("after buf = %s\n",buf);
// 大写发给客户端
ret = send(curfd,buf,strlen(buf)+1,0);
if(ret == -1) {
perror("send error");
exit(-1);
}
}
}
}
close(lfd);
return 0;
}
epoll_tl.c
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <errno.h>
// server
int main(int argc,const char* argv[]) {
// 创建监听的套接字
int lfd = socket(AF_INET,SOCK_STREAM,0);
if(lfd == -1) {
perror("socket");
exit(1);
}
// 绑定
struct sockaddr_in saddr;
memset(&saddr,0,sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(9999);
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
// inet_pton(AF_INET,"127.0.0.1",&saddr.sin_addr.s_addr);
// 设置端口复用
int optval = 1;
setsockopt(lfd,SOL_SOCKET,SO_REUSEPORT,&optval,sizeof(optval));
// setsockopt(lfd,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));
// 绑定端口
int ret = bind(lfd,(struct sockaddr*)&saddr,sizeof(saddr));
if(ret == -1) {
perror("bind");
exit(1);
}
// 监听
ret = listen(lfd,64);
if(ret == -1) {
perror("listen");
exit(1);
}
// 创建epoll 实例
int epfd = epoll_create(1);
if(epfd == -1) {
perror("epoll_create");
exit(-1);
}
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = lfd;
// 创建了epfd,设置lfd上需要检测事件并将lfd绑定到epfd
ret = epoll_ctl(epfd,EPOLL_CTL_ADD,lfd,&ev);
// epoll_ctl 调用成功返回0,调用失败返回-1,可以通过 errno 错误码获取具体的错误原因
if(ret == -1) {
perror("epoll_ctl");
close(lfd);
exit(1);
}
struct epoll_event evs[1024];
int size = sizeof(evs)/sizeof(evs[0]);
while (1) {
// epoll_wait 检测事件
int num = epoll_wait(epfd,evs,size,-1);
if(num < 0) {
// 被信号中断
if(errno == EINTR)
continue;
// 出错,退出
break;
} else if(num == 0) {
// 超时,继续
continue;
}
printf("num = %d\n",num);
for(int i = 0;i < num;i++) {
// ① 处理可读事件
if(evs[i].events & EPOLLIN) {
// 判断是否是监听套接字
int curfd = evs[i].data.fd;
// 如果是监听套接字,则处理连接请求
if(curfd == lfd) {
struct sockaddr_in caddr;
socklen_t len = sizeof(caddr);
int cfd = accept(lfd,(struct sockaddr*)&caddr,&len);
// 注意:传递给epoll_ctl之后,会做一个拷贝,其实可以不用再创建一个epoll_event ev
ev.events = EPOLLIN;
ev.data.fd = cfd;
epoll_ctl(epfd,EPOLL_CTL_ADD,cfd,&ev);
printf("accept a new client: %s:%d\n",inet_ntoa(caddr.sin_addr),ntohs(caddr.sin_port));
}
else {
// 如果是连接套接字,则处理读写事件
char buf[5];
int len = recv(curfd,buf,sizeof(buf),0);
if(len == -1) {
perror("recv error");
exit(1);
} else if(len == 0) {
printf("客户端已经断开连接...\n");
// 先删除
epoll_ctl(epfd,EPOLL_CTL_DEL,curfd,NULL);
// 再关闭
/*
注意:如果咱先关闭这个通信的文件描述符,然后再对这个节点进行删除
这个epoll_ctl会返回-1,也就说删除失败
*/
close(curfd);
}
printf("read buf = %s\n",buf);
// 小写转大写
for(int i=0;i<len;i++) {
buf[i] = toupper(buf[i]);
}
printf("after buf = %s\n",buf);
// 大写发给客户端
ret = send(curfd,buf,strlen(buf)+1,0);
if(ret == -1) {
perror("send error");
exit(1);
}
}
}
}
}
close(lfd);
return 0;
}
ep_et.c
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <errno.h>
#include <fcntl.h>
// server
int main(int argc,const char* argv[]) {
// 创建监听的套接字
int lfd = socket(AF_INET,SOCK_STREAM,0);
if(lfd == -1) {
perror("socket");
exit(1);
}
// 绑定
struct sockaddr_in saddr;
memset(&saddr,0,sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(9999);
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
// inet_pton(AF_INET,"127.0.0.1",&saddr.sin_addr.s_addr);
// 设置端口复用
int optval = 1;
setsockopt(lfd,SOL_SOCKET,SO_REUSEPORT,&optval,sizeof(optval));
// setsockopt(lfd,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));
// 绑定端口
int ret = bind(lfd,(struct sockaddr*)&saddr,sizeof(saddr));
if(ret == -1) {
perror("bind");
exit(1);
}
// 监听
ret = listen(lfd,64);
if(ret == -1) {
perror("listen");
exit(1);
}
// 创建epoll 实例
int epfd = epoll_create(1);
if(epfd == -1) {
perror("epoll_create");
exit(-1);
}
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = lfd;
// 创建了epfd,设置lfd上需要检测事件并将lfd绑定到epfd
ret = epoll_ctl(epfd,EPOLL_CTL_ADD,lfd,&ev);
// epoll_ctl 调用成功返回0,调用失败返回-1,可以通过 errno 错误码获取具体的错误原因
if(ret == -1) {
perror("epoll_ctl");
close(lfd);
exit(1);
}
struct epoll_event evs[1024];
int size = sizeof(evs)/sizeof(evs[0]);
while (1) {
// epoll_wait 检测事件
int num = epoll_wait(epfd,evs,size,-1);
if(num < 0) {
// 被信号中断
if(errno == EINTR)
continue;
// 出错,退出
break;
} else if(num == 0) {
// 超时,继续
continue;
}
printf("num = %d\n",num);
for(int i = 0;i < num;i++) {
// ① 处理可读事件
if(evs[i].events & EPOLLIN) {
// 判断是否是监听套接字
int curfd = evs[i].data.fd;
// 如果是监听套接字,则处理连接请求
if(curfd == lfd) {
struct sockaddr_in caddr;
socklen_t len = sizeof(caddr);
int cfd = accept(lfd,(struct sockaddr*)&caddr,&len);
// 设置非阻塞属性
int flag = fcntl(cfd,F_GETFL);
flag |= O_NONBLOCK;
fcntl(cfd,F_SETFL,flag);
// 注意:传递给epoll_ctl之后,会做一个拷贝,其实可以不用再创建一个epoll_event ev
ev.events = EPOLLIN | EPOLLET;
ev.data.fd = cfd;
epoll_ctl(epfd,EPOLL_CTL_ADD,cfd,&ev);
printf("accept a new client: %s:%d\n",inet_ntoa(caddr.sin_addr),ntohs(caddr.sin_port));
}
else {
// 如果是连接套接字,则处理读写事件
char buf[5];
while (1) {
int len = recv(curfd,buf,sizeof(buf),0);
if(len == -1) {
if(errno == EAGAIN) {
printf("数据已经接收完毕...\n");
break;
}else{
perror("recv error");
exit(1);
}
} else if(len == 0) {
printf("客户端已经断开连接...\n");
// 先删除
epoll_ctl(epfd,EPOLL_CTL_DEL,curfd,NULL);
// 再关闭
/*
注意:如果咱先关闭这个通信的文件描述符,然后再对这个节点进行删除
这个epoll_ctl会返回-1,也就说删除失败
*/
close(curfd);
break;
}
printf("read buf = %s\n",buf);
// 小写转大写
for(int i=0;i<len;i++) {
buf[i] = toupper(buf[i]);
}
printf("after buf = %s\n",buf);
write(STDERR_FILENO,buf,len);
// 大写发给客户端
ret = send(curfd,buf,strlen(buf)+1,0);
if(ret == -1) {
perror("send error");
exit(1);
}
}
}
}
}
}
close(lfd);
return 0;
}
基于多线程的边沿非阻塞处理
thread_epoll_et.c
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/epoll.h>
#include <iostream>
#include <string.h>
#include <errno.h>
int main(int argc,char* argv[]) {
// 创建一个侦听 socket
int lfd = socket(AF_INET,SOCK_STREAM,0);
if(lfd == -1) {
std::cout<<"create listen socket error"<<std::endl;
return -1;
}
// 将侦听socket设置为非阻塞的
int oldSocketFlag = fcntl(lfd,F_GETFL,0);
int newSocketFlag = oldSocketFlag | O_NONBLOCK;
int ret = fcntl(lfd,F_SETFL,newSocketFlag);
if(ret == -1) {
close(lfd);
std::cout<<"set listen socket nonblock error"<<std::endl;
return -1;
}
// 初始化服务器地址
struct sockaddr_in saddr;
saddr.sin_family = AF_INET;
saddr.sin_port = htons(9999);
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
ret = bind(lfd,(struct sockaddr*)&saddr,sizeof(saddr));
if(ret == -1) {
std::cout<<"bind error"<<std::endl;
close(lfd);
return -1;
}
// 启动侦听
ret = listen(lfd,10);
if(ret == -1) {
std::cout<<"listen error"<<std::endl;
close(lfd);
return -1;
}
// 复用地址和端口号
int optval = 1;
setsockopt(lfd,SOL_SOCKET,SO_REUSEADDR,(char*)&optval,sizeof(optval));
setsockopt(lfd,SOL_SOCKET,SO_REUSEPORT,(char*)&optval,sizeof(optval));
// 创建epfd
int epfd = epoll_create(10);
if(epfd == -1) {
std::cout<<"create epoll error"<<std::endl;
close(lfd);
return -1;
}
epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = lfd;
// 将lfd添加到epfd中
ret = epoll_ctl(epfd,EPOLL_CTL_ADD,lfd,&ev);
if(ret == -1) {
std::cout<<"epoll_ctl error"<<std::endl;
close(lfd);
return -1;
}
int n;
while (true) {
epoll_event evs[1024];
n = epoll_wait(epfd,evs,1024,-1);
if(n < 0) {
// 被信号中断
if(errno == EINTR)
continue;
// 出错,退出
break;
} else if(n == 0) {
// 超时,继续
continue;
}
for(int i = 0; i < n; i++) {
int curfd = evs[i].data.fd;
// 事件可读
if(evs[i].events & EPOLLIN) {
if(curfd == lfd) {
// 侦听socket,接受新连接
struct sockaddr_in caddr;
socklen_t clen = sizeof(caddr);
// 接受客户端连接,并加入到fds集合中
int cfd = accept(lfd,(struct sockaddr*)&caddr,&clen);
if(cfd != -1) {
// 将客户端socket设置为非阻塞的
int oldSockFlag = fcntl(cfd,F_GETFL,0);
int newSockFlag = oldSockFlag | O_NONBLOCK;
ret = fcntl(cfd,F_SETFL,newSockFlag);
if(ret == -1) {
close(cfd);
std::cout<<"set cfd to nonblock error"<<std::endl;
} else {
// epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = cfd;
ret = epoll_ctl(epfd,EPOLL_CTL_ADD,cfd,&ev);
if(ret != -1) {
std::cout<<"new cfd:"<<cfd<<" add to epoll success"<<std::endl;
} else {
std::cout<<"add cfd to epoll error"<<std::endl;
close(cfd);
}
}
}
}
else {
// 普通cfd,收取数据
char buf[64] = {0};
int m = recv(curfd,buf,64,0);
if(m == 0) {
// 对端关闭了连接,从epfd上移除cfd
ret = epoll_ctl(epfd,EPOLL_CTL_DEL,curfd,NULL);
if(ret == -1) {
std::cout<<"client disconnected,cfd: "<<curfd<<" remove from epoll error"<<std::endl;
}
close(curfd);
}
else if(m<0) {
// 出错,从epfd上移除cfd
if(errno!=EWOULDBLOCK && errno!=EINTR) {
ret = epoll_ctl(epfd,EPOLL_CTL_DEL,curfd,NULL);
if(ret == -1) {
std::cout<<"client disconnected,cfd: "<<curfd<<" remove from epoll error"<<std::endl;
}
close(curfd);
}
}
else {
// 正常收到数据
std::cout<<"recv from client: "<<buf<<",cfd: "<<curfd<<std::endl;
}
}
}
else if(evs[i].events&EPOLLERR) {
// TODO: 暂且不处理
}
}
}
// 关闭侦听 socket
close(lfd);
return 0;
}
thread_client.c
#include <stdio.h>
#include <ctype.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
// nestat -anp | grep
int main(int argc,char* argv[]) {
int fd = socket(AF_INET,SOCK_STREAM,0);
if(fd == -1) {
perror("socket");
return -1;
}
struct sockaddr_in saddr;
saddr.sin_family = AF_INET;
saddr.sin_port = htons(9999);
inet_pton(AF_INET,"127.0.0.1",&saddr.sin_addr.s_addr);
// 连接服务器
int ret = connect(fd,(struct sockaddr*)&saddr,sizeof(saddr));
if(ret == -1) {
perror("connect");
return -1;
}
int num = 0;
char buf[1024] = {0};
while (num < 200) {
sprintf(buf,"hello world %d\n...",num++);
printf("%s\n",buf);
write(fd,buf,strlen(buf) + 1);
recv(fd,buf,sizeof(buf),0);
printf("recv msg: %s\n",buf);
usleep(100000);
}
close(fd);
return 0;
}
实验效果(截取部分):
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 164
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 121
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 142
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 165
...communication tid: 140537394865920
HELLO WORLD 122
...数据已经接收完毕...
数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 143
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLOcommunication tid: 140537394865920
WORLHELLOD 166 WORLD 123
...
...数据已经接收完毕...
数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 144
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 167
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 124
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 145
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 168
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 125
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 146
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 169
...communication tid: 140537555547904
HELLO WORL数据已经接收完毕...
D 126
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 147
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 170
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 127
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 148
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 171
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 128
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 149
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 129
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 172
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 150
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 173
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 130
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 151
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLOcommunication tid: 140537394865920
WORLHELLOD 174 WORL
...D 131数据已经接收完毕...
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 152
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 175
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 132
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 153
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 133
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 176
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 154
...数据已经接收完毕...
num = 1
打印tid:140537555547904
num = 1
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 134
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 177
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 155
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 135
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 178
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 156
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 179
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 136
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 157
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 137
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 180
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 158
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537555547904
communication tid: 140537394865920
HELLOHELLO WORL WORLD 181D 138
...
...数据已经接收完毕...
数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 159
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 182
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 139
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 160
...数据已经接收完毕...
num = 1
打印tid:140537394865920
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLOcommunication tid: 140537555547904
HELLO WORL WORLD 183D 140
...
...数据已经接收完毕...
数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 161
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 184
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 141
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 162
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLcommunication tid: 140537394865920
D 185HELLO
... WORL数据已经接收完毕...
D 142
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 163
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 186
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 143
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 164
...数据已经接收完毕...
num = 2
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 187
...数据已经接收完毕...
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 144
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 165
...数据已经接收完毕...
num = 1
打印tid:140537555547904
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 188
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 145
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 166
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 146
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 189
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 167
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 190
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 147
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 168
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
communication tid: 140537555547904
HELLO WORLD 191HELLO
...数据已经接收完毕...
WORLD 148
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 169
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 192
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 149
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 170
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 150
...communication tid: 140537555547904
HELLO WORLD 193
...数据已经接收完毕...
数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 171
...数据已经接收完毕...
num = 2
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 194
...数据已经接收完毕...
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 151
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 172
...数据已经接收完毕...
num = 1
打印tid:140537555547904
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 195
...数据已经接收完毕...
communication tid: 140537394865920
HELLO WORLD 152
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 173
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 196
...communication tid: 140537394865920
HELLO WORLD 153
...数据已经接收完毕...
数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 174
...数据已经接收完毕...
num = 2
打印tid:140537394865920
打印tid:140537394865920
communication tid: 140537394865920
HELLO WORLD 197
...communication tid: 140537555547904
HELLO WORLD 154
...数据已经接收完毕...
数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 175
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 155
...数据已经接收完毕...
communication tid: 140537555547904
HELLO WORLD 198
...数据已经接收完毕...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 176
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 156
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 199
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 177
...数据已经接收完毕...
num = 2
打印tid:140537555547904
打印tid:140537555547904
communication tid: 140537394865920
HELLO WORLD 157
...数据已经接收完毕...
communication tid: 140537555547904
客户端已经断开连接...
num = 1
打印tid:140537394865920
communication tid: 140537555547904
HELLO WORLD 178
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 158
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 179
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 159
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 180
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 160
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 181
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 161
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 182
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 162
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 183
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 163
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 184
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 164
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 185
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 165
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 186
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 166
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 187
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 167
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 188
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 168
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 189
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 169
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 190
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 170
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 191
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 171
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 192
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 172
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 193
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 173
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 194
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 174
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 195
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 175
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 196
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 176
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 197
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 177
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 198
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 178
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 199
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 179
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
客户端已经断开连接...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 180
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 181
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 182
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 183
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 184
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 185
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 186
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 187
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 188
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 189
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 190
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 191
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 192
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 193
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 194
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 195
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 196
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 197
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 198
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
HELLO WORLD 199
...数据已经接收完毕...
num = 1
打印tid:140537555547904
communication tid: 140537555547904
客户端已经断开连接...