当前位置: 技术问答>linux和unix
socket中的一段代码,debug可以,直接运行就不可以。
来源: 互联网 发布时间:2016-09-20
本文导语: while(1) { timeout.tv_sec = 10; timeout.tv_usec = 0; FD_ZERO(&readfds); FD_SET(newsockfd,&readfds); rt = select(newsockfd + 1,&readfds,NULL,NULL,&timeout); if(rt == SOCKET_ERROR) { printf("socket error when select! n"); break; } if(FD_ISSET(newsockf...
while(1)
{
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&readfds);
FD_SET(newsockfd,&readfds);
rt = select(newsockfd + 1,&readfds,NULL,NULL,&timeout);
if(rt == SOCKET_ERROR)
{
printf("socket error when select! n");
break;
}
if(FD_ISSET(newsockfd,&readfds))
{
if(flag == 0)
{
if(recv(newsockfd,&sd_communication_header_variable,sizeof(sd_communication_header_variable),0) > 0)
{
if(!read_profile_string("Version","CurrentVersion",ini,BUF_SIZE,"",inifile_chanpin))
{
printf("read ini file failn");//这里可能因为多线程的原因显示不出来,BUF_SIZE的大小也要考虑,不能全部4100
return;
}
else
{
if(ProductVersionisOk(ini,sd_communication_header_variable.dwProductVersion) != 0)
{
printf("客户端与服务器版本不正确!n");//这里看看是不是一定要每收到个包头判断版本号
return;
}
}
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&writefds);
FD_SET(newsockfd,&writefds);
rt = select(newsockfd + 1,NULL,&writefds,NULL,&timeout);
if(rt == SOCKET_ERROR)
{
printf("socket error when select! n");
break;
}
if(FD_ISSET(newsockfd,&writefds))
{
if(send(newsockfd,"I got your message",18,0)