Z
zyjba
Unregistered / Unconfirmed
GUEST, unregistred user!
大侠们好,初次写数据接收的代码,不知道下面的代码运行有没有漏洞,我测试是没什么问题。如有问题,请大侠帮忙改正一下,谢谢procedure Tfrmmain.TcpServerAccept(Sender: TObject; ClientSocket: TCustomIpClient);var RCount: integer; Rbuf: array[0..8191] of Byte; Buf:TMemoryStream;begin try Buf := TMemoryStream.Create; {开始接收} while ClientSocket.Connected do if ClientSocket.WaitForData(5000) then //如果5秒钟没有数据到来,则断开 begin RCount := ClientSocket.ReceiveBuf(Rbuf, 8192); Buf.WriteBuffer(Rbuf, RCount); if RCount <= 0 then ClientSocket.Disconnect; end else ClientSocket.Disconnect;// {接收完毕} finally Buf.Free; end;end;