当前位置: 技术问答>linux和unix
linux网络开发问题,为何双方一直阻塞收不到信息
来源: 互联网 发布时间:2016-02-21
本文导语: server.c const int MAX_SOCK_LEN = 10; int sockfd,socklen,icount,clientfd,client_len,server_len; int result,nread; char ch[2] = {0} ; sockaddr_in serveraddr,clientaddr; fd_set readfds,testfds; sockfd = create(AF_INET,STREAM_SOCK,0); sock_arr[0] = sockfd; ...... //...
server.c
const int MAX_SOCK_LEN = 10;
int sockfd,socklen,icount,clientfd,client_len,server_len;
int result,nread;
char ch[2] = {0} ;
sockaddr_in serveraddr,clientaddr;
fd_set readfds,testfds;
sockfd = create(AF_INET,STREAM_SOCK,0);
sock_arr[0] = sockfd;
...... // 初始sock结构省略
FD_ZERO(&readfds);
FD_SET(sock_arr[0],&readfds);
testfds = readfds;
server_len = sizeof(serveraddr);
bind(sockfd,(struct sockaddr *)&serveraddr,server_len);
listen(sockfd,5);
while(1)
{
result = select(MAX_SOCK_LEN+1,&testfds,(fd_set*)NULL,(fd_set*)NULL,(struct timeval *)0);
...... //判断result省略
icount = 3;
while(icount
const int MAX_SOCK_LEN = 10;
int sockfd,socklen,icount,clientfd,client_len,server_len;
int result,nread;
char ch[2] = {0} ;
sockaddr_in serveraddr,clientaddr;
fd_set readfds,testfds;
sockfd = create(AF_INET,STREAM_SOCK,0);
sock_arr[0] = sockfd;
...... // 初始sock结构省略
FD_ZERO(&readfds);
FD_SET(sock_arr[0],&readfds);
testfds = readfds;
server_len = sizeof(serveraddr);
bind(sockfd,(struct sockaddr *)&serveraddr,server_len);
listen(sockfd,5);
while(1)
{
result = select(MAX_SOCK_LEN+1,&testfds,(fd_set*)NULL,(fd_set*)NULL,(struct timeval *)0);
...... //判断result省略
icount = 3;
while(icount