Ver Mensaje Individual
  #1  
Antiguo 27-07-2008
cmm07 cmm07 is offline
Miembro
 
Registrado: nov 2007
Posts: 526
Reputación: 19
cmm07 Va por buen camino
archivos e Indy

Hola, delphianos, tengo una duda, todavia estoy con eso de transferir archivos, me aburrí de intentar con Socket asi que me cambien al componente de las indy (IdTCPClient e IdTCPServer), ví un ejemplo en delphi sobre esto pero al agregarla a mi aplicación me crea un archivo de 0kb, utilizo la sig.intruccion:

Cliente
Código Delphi [-]

unit fClient;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient,IdGlobal;

type
  TfrmClient = class(TForm)
    imgMain: TImage;
    btnGetSelectedImage: TButton;
    Label2: TLabel;
    edtServerHost: TEdit;
    IdTCPClient: TIdTCPClient;
    Label3: TLabel;
    Label4: TLabel;
    edtServerPort: TEdit;
    procedure btnGetSelectedImageClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmClient: TfrmClient;

implementation

{$R *.DFM}

procedure TfrmClient.btnGetSelectedImageClick(Sender: TObject);
var
    ftmpStream : TFileStream;
begin
with IdTCPClient do
    begin
    if connected then DisConnect;
    Host := edtServerHost.text;
    Port := StrToInt(edtServerPort.text);
    Connect;
    WriteLn('PIC');
    ftmpStream := TFileStream.Create('C:\abc.bmp',fmCreate);
    while connected do
        ReadStream(fTmpStream,-1,true);
    FreeAndNil(fTmpStream);
    Disconnect;
end;
end;

end.

y este el server:

Código Delphi [-]
unit fServer;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, IdBaseComponent, IdComponent, IdTCPServer, StdCtrls,IdGlobal,
  SyncObjs;

type
  TfrmServer = class(TForm)
    IdTCPServer: TIdTCPServer;
    lstRequests: TListBox;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure IdTCPServerExecute(AThread: TIdPeerThread);
  private
    { Private declarations }
  public
    { Public declarations }
  CS : TCriticalSection;
  end;

var
  frmServer: TfrmServer;
  sFilePattern : String;

implementation

{$R *.DFM}

procedure TfrmServer.FormCreate(Sender: TObject);
begin
CS := TCriticalSection.Create;
idTCPServer.Active := true;
end;

procedure TfrmServer.IdTCPServerExecute(AThread: TIdPeerThread);
var
    s, sCommand, sAction : string;
    fStream : TFileStream;
    tBM : tbitmap;
begin
CS.Enter;
s := uppercase(AThread.Connection.ReadLn);
sCommand := copy(s,1,3);
if sCommand = 'PIC' then
begin
fStream := TFileStream.Create('images\Connect.bmp',fmOpenRead    + fmShareDenyNone);
AThread.Connection.OpenWriteBuffer;
AThread.Connection.WriteStream(fStream);
AThread.Connection.CloseWriteBuffer;
FreeAndNil(fStream);
End;
end;

end.

no se si puedes chequiarlo y ver que esta mal?? o que falta??

gracias
54LU2
Responder Con Cita