在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
https://www.cnblogs.com/zhangzhifeng/p/6065244.html
TServerSocket和TClientSocket用非阻塞模式发送和接收比较大的数据时,可能一次会接收不完,此时需要通过循环接收。
//接收 procedure TMAINFORM.TCPServer1ClientRead(Sender: TObject; Socket: TCustomWinSocket); var iLength,I,iStart, iRevCount: Integer; iReceived: Integer; buff: array of byte; S:STRING; begin S:=''; iStart := 0; iLength:= Socket.ReceiveLength; iRevCount := iLength; //这里加入的 SetLength(buff, iLength); MEMO1.Lines.Add(INTTOSTR(ILENGTH)); while iLength>0 do begin iReceived := Socket.ReceiveBuf(buff[iStart], iLength); //这里修改了注意 iStart := iStart + iReceived ; //这里加入的 iLength := iLength - iStart; end; //下面你的iLength 使用 iRevCount 替换了 FOR I:=0 TO iRevCount -1 DO BEGIN S:=S+INTTOSTR(BUFF[I]); END; MEMO1.Lines.Add(S); buff:= nil; end;
发送:Socket.SendBuf
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论