在INDY中的Idtcpclient的readln方法中,是不是没有读到就一直等待???
还有象这句IdTCPClient1.ReadLn(#13#10,1000);中的1000 文档里说是超时参数. 可这里指什么超时? 超了时又会怎么样?? 好象看不出来. 
大侠能不能占用你一点时间,帮我解决一下,搞了很久了,就是没搞定!!!!!!!!procedure TfmClient.Button1Click(Sender: TObject);
var
 Buf : array[0..1023] of Byte;
 ReadCount : Integer;
 aStream : TFileStream;
 aSize : Integer;
 aFileName : String;
begin
 if OpenDialog1.Execute then
 begin
   IdTCPClient1.Connect;
   aStream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead or fmShareDenyWrite);
   try
     //发送文件名
     aFileName := ExtractFileName(OpenDialog1.FileName);
     IdTCPClient1.WriteLn(aFileName);
     //等待接受确认
    edit3.Text:= IdTCPClient1.ReadLn(#13#10,1000);  ////如果服务器没有执行那条writeln则程序一直等在此句里??????????????????????????
     //写文件长度和文件流
     aSize := aStream.Size;
     ProgressBar1.Max := aSize;
     IdTCPClient1.WriteBuffer(aSize, 4);
     //IdTCPClient1.WriteStream(aStream);
     while aStream.Position < aStream.Size do
     begin
       if aStream.Size - aStream.Position >= SizeOf(Buf) then
         ReadCount := sizeOf(Buf)
       else
         ReadCount := aStream.Size - aStream.Position;
       aStream.ReadBuffer(Buf, ReadCount);
       IdTCPClient1.WriteBuffer(Buf, ReadCount);
       ProgressBar1.Position := aStream.Position;
       Application.ProcessMessages;
     end;
     Caption := IdTCPClient1.ReadLn;
     IdTCPClient1.Disconnect;
   finally
     edit3.Text:='finally';
     aStream.Free;
   end;
 end;
end;
=======================
procedure TfmServer.IdTCPServer1Execute(AThread: TIdPeerThread);
var
 aFileSize : Integer;
 aFileName : String;
 Buff : array[0..1023] of Byte;
 ReadCount : Integer;
begin
 with AThread.Data as TThreadData do
 begin
   if State = dstNone then
   begin
     if not AThread.Terminated and AThread.Connection.Connected then
     begin
       //读取文件名
       aFileName := AThread.Connection.ReadLn(#13#10, 100);
       if aFileName = '' then
         Exit;
       SaveDialog1.FileName := aFileName;
      // if SaveDialog1.Execute then
       //begin
         //返回确认文件传输标志-----------如果把下面一句注释了,则客户端会一直停在如上所注的那行!!!!!!!!!!!!!!!!!!!!!1不知为何????
         AThread.Connection.WriteLn('test');  
         //开始读取文件长度,创建文件
         AThread.Connection.ReadBuffer(aFileSize, 4);
         FileSize := aFileSize;
         ProgressBar1.Max := FileSize;
         Stream := TFileStream.Create('i:\' +aFileName, fmCreate);
         State := dstReceiving;
       //end
       //else
        // AThread.Connection.Disconnect
     end;
   end else begin
     if not AThread.Terminated and AThread.Connection.Connected then
     begin
       //读取文件流
       repeat
         if FileSize - Stream.Size > SizeOf(Buff) then
           ReadCount := SizeOf(Buff)
         else
           ReadCount := FileSize - Stream.Size;
         AThread.Connection.ReadBuffer(Buff, ReadCount);
         Stream.WriteBuffer(Buff, ReadCount);
         ProgressBar1.Position := Stream.Size;
         Caption := IntToStr(Stream.Size) + '/' + IntToStr(FileSize);
         Application.ProcessMessages;
       until Stream.Size >= FileSize;
       AThread.Connection.WriteLn('OK');
       Stream.Free;
       Stream := nil;
       State := dstNone;
     end;
   end;
 end;
end;

解决方案 »

  1.   

    IdTCPClient1.ReadLn;
    如果IdTCPClient1超时属性为0将一直等下去,直到有一行数据进来
    IdTCPClient1.ReadLn(#13#10,1000);
    如果过了1秒没数据就不等了,不过也没有数据读进来,可以报错了。
      

  2.   

    我更新了9.14的indy组件,仍然有这个问题,不返回。即使设置了readtimeout属性(比如说1000),也不会产生异常。
    补充一下,我是在线程中使用的。
      

  3.   

    結案啦?那只好給大家自己去參考我的解決方案啦!這是IDTcpConnection的bug,解決方法如下~~~~procedure timer.ontimer.................
    var temp:string;
    begin
       idtcpclient.readfromstack(false,1,false);
       while idtcpclient.InputBuffer.Size>0 do begin
          temp:=idtcpclient.ReadLn;        
       end;
    end;
    藏私の禁止發表人 - japhenchen 於 2004/04/23 18:08:29
      

  4.   

    idtcpclient是一个新生的控件还不太完善,大家用这的时候注意
      

  5.   

    可以创建一个线程专门去监听端口,不要发送之后就直接readln()来等待返回消息。