怎么用idtcpserver和idtcpclient来发送和接收流啊?
TIdTCPConnection.WriteStream(AStream: TStream; const AAll: boolean = true;
const AWriteByteCount: Boolean = False; const ASize: Integer = 0);
里后面几个参数是什么意思?
readstream的参数又是什么意思?它怎么知道stream的长度是多少,怎么知道接收完没有?

解决方案 »

  1.   

    有WRITE肯定有READ嘛。否则不成了只吃不拉了嘛?^_^
    至于参数的含义你可以按F1,它会告诉你的。^_^
    如果你不喜欢READSTREAM,可以用WRITEBUFF自己设定缓冲区大小。
      

  2.   

    Sends a stream of data to the peer connection.procedure WriteStream(AStream: TStream; const AAll: Boolean = True; const AWriteByteCount: Boolean = False; const ASize: Integer = 0); virtual;ParametersAStream: TStreamThe stream to send to the peer connection.const AAll: Boolean = TrueWrite from the start of the stream. Default value is True.const AWriteByteCount: Boolean = FalseWrite the stream sizew to the peer connection. Default value is False.DescriptionWriteStream is a procedure used to send the contents of the TStream descendant specified in AStream to the peer connection.AAll indicates that the stream should be positioned to the stream origin prior to sending stream data.AWriteByteCount indicates that the Integer value containing the size of the stream should be written to the peer connection prior to the stream data. When AAll is true, this value reflects the size of the entire stream. When AAll is False, this value indicates the stream sixe from the current stream position to the end of the stream. When AWriteByteCount is True, WriteInteger is called to send the stream size to the peer connection.WriteStream calls BeginWork with the work mode wmWrite and the size of the stream prior to sending stream data to the peer connection. The stream size is the value in AStream.Size, and is stored in a variable for subsequent use in the method. This reduces the overhead for TStream descendants where TStream.Seek is not efficient or practical.AStream data is sent to the peer in blocks, where each block is read into a buffer that can contain up to SendBufferSize bytes. If a read from AStream results in a buffer with a length of 0, when the stream size and position indicate a non-zero value, an EIdNoDataToRead exception will be raised. Data read from AStream is sent on the connection using WriteBuffer with the current buffer contents and size.WriteStream calls EndWork with the work mode wmWrite prior to exiting from the method.
      

  3.   

    能不能举个列子,发送一个完整的stream和接收一个完整的stream,参数一般怎么写?
      

  4.   

    发送端
    procedure TForm1.Button2Click(Sender: TObject);
    var
     buf:tfilestream;
    begin
     buf := TFileStream.Create(edit5.Text, fmOpenRead);//edit5.text文件名(含路径)
     IdTCPClient1.Host:=edit1.Text;//ip  string;
     IdTCPClient1.Port:=1053;
     IdTCPClient1.Connect();
     IdTCPClient1.WriteLn(ExtractFileName(edit5.Text));
     IdTcpClient1.WriteStream(buf,true,true); //发送文件
     IdTcpClient1.Disconnect;
     buf.Free;
    end;
    接收端
    procedure Tfm_main.IdTCPServer1Execute(AThread: TIdPeerThread);
    var
     buf: TFileStream;
     FileName:string;
     size:longint;
    begin
    //  IdTCPServer1.Bindings:='0.0.0.0:1053'
    //  IdTCPServer1.active:=true;             //预先在属性设置好
     FileName:=athread.Connection.ReadLn;
     buf := TFileStream.Create(FileName, fmCreate);
     AThread.Connection.ReadStream(buf, -1, true);
     buf.Free;
    end;
     
            看你给多少分?                     ^Q^
      

  5.   

    http://www.513soft.net:83/qlj/trans.rar