Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   archivos e Indy (https://www.clubdelphi.com/foros/showthread.php?t=58654)

cmm07 27-07-2008 22:20:45

archivos e Indy
 
Hola, delphianos, tengo una duda, todavia estoy con eso de transferir archivos:D:D, 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

JXJ 28-07-2008 03:04:02

'¿version de indy que usas?

cmm07 28-07-2008 05:02:37

version 9 de las indy


La franja horaria es GMT +2. Ahora son las 11:53:14.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi