如何判断WSAAsyncSelect(异步模式)下数据已经接收完成(100分)

  • 主题发起人 主题发起人 micro73
  • 开始时间 开始时间
M

micro73

Unregistered / Unconfirmed
GUEST, unregistred user!
我用winsock下载网页,如何判断WSAAsyncSelect(异步模式)下数据已经接收完成?
Procedure TForm1.SockEvent(var Msg:TMessage);
var
recLen:Integer;
str:string;
Begin
//LstLog.Items.Insert(0,'Sock Event raised!');
case msg.LParamLo of
FD_CONNECT:
Begin
Connected:=true;
LstLog.Items.append('Connect to Server!');
lstlog.ItemIndex:=lstlog.Items.Count-1;
End;
FD_WRITE:
Begin
SendStr:=GetHttpStrSend;
strCopy(pchar(@SEndBuf),pchar(SendStr));
//stm.WriteString('asdfasdfasdfasdfds');
//stm.Read( SendBuf,length(sendstr));
//showMessage(sendbuf);
//ShowMessage(SendBuf[0 - (length(sendstr)-1)]);
If Connected THen
send(sock,SendBuf,length(sendstr),0);
LstLog.Items.append('Data Send.');
lstlog.ItemIndex:=lstlog.Items.Count-1;
End;
FD_READ:
Begin
//showMessage(RecBuf);
RecLen:= recv(sock,RecBuf,65536,0);
showmessage(inttostr(reclen));
fstream.Position:=fStream.Size;
fStream.WriteBuffer(Recbuf,RecLen);
if reclen=-1 then
begin
fstream.Position:=0;
SetLength(str, fstream.size);
Move(pchar(fstream.memory)^, str[1], fstream.Size);
memo1.text:=str;
end;
//ShowMessage(recbuf);
RecStr:=copy(RecBuf,0,RecLen);
self.MemoRec.Lines.Text:=self.MemoRec.Lines.Text+(RecStr); //[0 - (RecLen-1)]
LstLog.Items.append('Data Arrived, length:'+inttostr(reclen));
lstlog.ItemIndex:=lstlog.Items.Count-1;
End;
FD_CLOSE:
Begin
Connected:=false;
//CloseSocket(sock);
LstLog.Items.append('Connection closed!');
lstlog.ItemIndex:=lstlog.Items.Count-1;
Self.BtnRequest.Enabled:=true;
self.BtnCancel.Enabled:=false;
End;
End;
End;
 
没人知道吗?
 
后退
顶部