问题描述
为什么do下面第一次执行的时候,availCount都是0,sleep一次之后就不会为0了。。do{availCount=client.Available;num=client.Receive(data,availCount<ResponseByteLength?availCount:ResponseByteLength,SocketFlags.None);responseData+=loacalEncoding.GetString(data,0,num);SiteLog.WriteLog(LogType.FactLog,"data:"+responseData);SiteLog.WriteLog(LogType.FactLog,num.ToString());if(num<=0){SiteLog.WriteLog(LogType.FactLog,"sleep");System.Threading.Thread.Sleep(10);timer++;}if(timer>=DapTime*100)//30秒钟没有应答则自动退出!{SiteLog.WriteLog(LogType.FactLog,"30s内无应答,超时退出!");SiteLog.WriteLog(LogType.ErrorLog,"30s内无应答,超时退出!");break;}}while(client.Available>0);
解决方案
解决方案二:
数据少的时候还能接收完整。如果数据多了,就接收不完了。。但能接收到正确的结束标识。。好怪
时间: 2024-10-14 18:40:58