时
时报平
Unregistered / Unconfirmed
GUEST, unregistred user!
我本来设定的是非阻塞模式(ctNonBlocking),在ClientSocketRead事件中接收,但是接收到的文件不完整,每次大小都不一样。
但是设为阻塞模式(ctBlocking)后,我直接在发送的代码后面加上接收代码,竟然行了。
try
ClientSocket1.Socket.SendBuf(DataheadFS,sizeof(DataheadFS));
while ClientSocket1.Socket.ReceiveBuf(DataheadRev,sizeof(DataheadRev))>0 do
begin
DataheadRev.datatype := ntohs(DataheadRev.datatype);
DataheadRev.datalen := ntohl(DataheadRev.datalen);
if DataheadRev.datatype=1002 then
begin
bit_Insert.enabled := True;
BitBtn1.Enabled := True;
StatusBar1.Panels[1].Text := '';
end;
if DataheadRev.datatype=1001 then
if (DataheadRev.datalen>0) and (DataheadRev.datalen<=512) then
begin
for i := 0 to (DataheadRev.datalen -1) do
writeTofile(DataheadRev.filename,DataheadRev.datas);
srcFileName := DataheadRev.filename;
end;
ClientSocket1.Socket.Sendtext('OK');
StatusBar1.Panels[1].Text := ......';
Application.ProcessMessages;
end;
finally
//ClientSocket1.Active := False
end;
哪位讲讲道理是什么?
但是设为阻塞模式(ctBlocking)后,我直接在发送的代码后面加上接收代码,竟然行了。
try
ClientSocket1.Socket.SendBuf(DataheadFS,sizeof(DataheadFS));
while ClientSocket1.Socket.ReceiveBuf(DataheadRev,sizeof(DataheadRev))>0 do
begin
DataheadRev.datatype := ntohs(DataheadRev.datatype);
DataheadRev.datalen := ntohl(DataheadRev.datalen);
if DataheadRev.datatype=1002 then
begin
bit_Insert.enabled := True;
BitBtn1.Enabled := True;
StatusBar1.Panels[1].Text := '';
end;
if DataheadRev.datatype=1001 then
if (DataheadRev.datalen>0) and (DataheadRev.datalen<=512) then
begin
for i := 0 to (DataheadRev.datalen -1) do
writeTofile(DataheadRev.filename,DataheadRev.datas);
srcFileName := DataheadRev.filename;
end;
ClientSocket1.Socket.Sendtext('OK');
StatusBar1.Panels[1].Text := ......';
Application.ProcessMessages;
end;
finally
//ClientSocket1.Active := False
end;
哪位讲讲道理是什么?