我在服务器那边传输的流大小是17个字节,但是在客户端那边却有85个字节,打开文件全部都是乱码来的
server:
procedure TForm1.serverExecute(AThread: TIdPeerThread);
var
  intfilesize:int64;
begin
  if edtpath.Text <>'' then
  begin
    try try
      if not assigned(fs) then
      begin
        fs:=tfilestream.Create(edtpath.text,fmopenread);
        fs.Position:=0;
        showmessage(inttostr(fs.size));
      end;      athread.connection.WriteStream(fs,false,true,FILESIZE);      if fs.Position =fs.Size then
        athread.Connection.Disconnect;
    except on ex:exception do
      raise exception.Create(ex.Message );
    end;
    finally
      if fs.Position =fs.Size then
        fs.Free;
    end;
  end;
end;client:
 try try
    if not client.Connected then
    begin
      client.Host:='127.0.0.1';
      client.Port:=8080;
      client.Connect();
    end;    ms:=tmemorystream.Create;
    client.readstream (ms,1,true);
    showmessage(inttostr(ms.size));
    ms.SaveToFile('d:\text.txt');
  except on ex:exception do
    raise exception.Create(ex.Message );
  end;
  finally
    ms.Free;
  end;

解决方案 »

  1.   

    ///////////athread.connection.WriteStream(fs,false,true,fs.size);
      

  2.   

    学习!我是菜鸟!
    --------------------------------
    我的网站,支持一下:www.517yn.net
      

  3.   

    athread.connection.writeinteger(fs.size); // 先发大小
           athread.connection.openwritebuffer;
            try
              athread.connection.writestream(fs);  //发送流
              athread.connection.closewritebuffer;
            except
              athread.connection.cancelwritebuffer;
            end;
    好象是这么做!
      

  4.   

    client.readstream (ms,1,true); 错了
    应该
    client.readstream (ms^,1,true);