GARANTIR DESCONTO

Fórum Integração Automatica...interessante #179139

02/09/2003

0

Criei um prog q usa NMStrm e NMStrmServ, para fazer a atualização do de dados DBF para isso via DOS tem um prog q cria um pacote com os dados e meu prog em Delphi tem q pegar os pacotes e enviar para as outras filiais, so q tem um problema quando tentei enviar ontem varios pacotes (18000), quando chegava proximo do 8000 a maquina travava, erro do Windows...
Mando a seguir o codigo para tentar ter ajuda...

unit strmdem;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, NMStrm,
  ExtDlgs, StdCtrls, Psock, ExtCtrls, ComCtrls, DB, DBTables, FileCtrl;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    NMStrm1: TNMStrm;
    NMStrmServ1: TNMStrmServ;
    StatusBar1: TStatusBar;
    FileListBox1: TFileListBox;
    Envia: TTable;
    Timer1: TTimer;
    Recebe: TTable;
    Label1: TLabel;
    procedure NMStrmServ1MSG(Sender: TComponent; const sFrom: String;
      strm: TStream);
    procedure NMStrm1Connect(Sender: TObject);
    procedure NMStrm1Disconnect(Sender: TObject);
    procedure NMStrm1HostResolved(Sender: TComponent);
    procedure NMStrm1Status(Sender: TComponent; Status: String);
    procedure NMStrm1PacketSent(Sender: TObject);
    procedure NMStrm1InvalidHost(var handled: Boolean);
    procedure NMStrm1ConnectionFailed(Sender: TObject);
    procedure NMStrmServ1ClientContact(Sender: TObject);
    procedure NMStrmServ1Status(Sender: TComponent; Status: String);
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure NMStrmServ1ConnectionFailed(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormShow(Sender: TObject);
begin
  Timer1Timer(nil);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  MyFStream: TFileStream;
  filial: string;
  i: integer;
begin
  Timer1.Enabled := false;
  Envia.First;
  while not Envia.Eof do
  begin
    FileListBox1.Update;
    FileListBox1.Directory := Envia.FieldByName(´envia´).AsString;
    NMStrm1.Host := Envia.FieldByName(´ip´).AsString;

    for i := 0 to FileListBox1.Items.Count - 1 do
    begin
      Filial := copy(FileListBox1.Items[I],2,2);
      if StrToInt(filial) <> Envia.FieldByName(´filial´).AsInteger then
      begin
        NmStrm1.FromName := FileListBox1.Items[I];
        MyFStream := TFileStream.Create(FileListBox1.Items[I], fmOpenRead);
        try
          NMStrm1.PostIt(MyFStream);
        finally
          MyFStream.Free;
          DeleteFile(FileListBox1.Items[I]);
        end;
      end;
    end;
    Envia.Next;
  end;
  Timer1.Enabled := true;
end;

procedure TForm1.NMStrmServ1MSG(Sender: TComponent; const sFrom: String;
  strm: TStream);
var
  MyFStream: TFileStream;
begin
  label1.Caption := sFrom;
  if directoryexists(Recebe.FieldByName(´recebe´).AsString) then
  begin
    MyFStream := TFileStream.Create(Recebe.FieldByName(´recebe´).AsString + sFrom, fmCreate);
  end
  else
  begin
    ForceDirectories(Recebe.FieldByName(´recebe´).AsString);
    MyFStream := TFileStream.Create(Recebe.FieldByName(´recebe´).AsString + sFrom, fmCreate);
  end;
  try
    MyFStream.CopyFrom(strm, strm.size);
  finally
    Label1.Caption := ´ ´;
    MyFStream.Free;
  end;
end;

procedure TForm1.NMStrm1Connect(Sender: TObject);
begin
//  StatusBar1.SimpleText := ´Enviando´;
end;

procedure TForm1.NMStrm1Disconnect(Sender: TObject);
begin
  If StatusBar1 <> nil then
    StatusBar1.SimpleText := ´Aguardando...´;
end;

procedure TForm1.NMStrm1HostResolved(Sender: TComponent);
begin
  StatusBar1.SimpleText := ´Host Resolved´;
end;

procedure TForm1.NMStrm1Status(Sender: TComponent; Status: String);
begin
//  If StatusBar1 <> nil then
//    StatusBar1.SimpleText := status;
end;

procedure TForm1.NMStrm1PacketSent(Sender: TObject);
begin
  StatusBar1.SimpleText := IntToStr(NMStrm1.BytesSent) + ´ de ´ + IntToStr(NMStrm1.BytesTotal) + ´ enviados´;
end;

procedure TForm1.NMStrm1InvalidHost(var handled: Boolean);
var
  TmpStr: String;
begin
  if Envia.Eof then
  begin
    If InputQuery(´Host invalido!´, ´Especifique um novo host:´, TmpStr) then
    Begin
      NMStrm1.Host := TmpStr;
      Handled := TRUE;
    End;
  end
  else
  begin
    NMStrm1.Host := Envia.FieldByName(´ip´).AsString;
    Handled := TRUE;
  end;
end;

procedure TForm1.NMStrm1ConnectionFailed(Sender: TObject);
begin
  if Envia.Eof then
  begin
    ShowMessage(´Erro na conexão!´);
  end;
  FileListBox1.Directory := Envia.FieldByName(´envia´).AsString;
  NMStrm1.Host := Envia.FieldByName(´ip´).AsString;
  if NMStrm1.Connected = false then
  begin
    Envia.Next;
  end;
end;

procedure TForm1.NMStrmServ1ConnectionFailed(Sender: TObject);
begin
  ShowMessage(´Erro ao conectar!´);
end;

procedure TForm1.NMStrmServ1ClientContact(Sender: TObject);
begin
  NMStrmServ1.ReportLevel := Status_Basic;
  NMStrmServ1.TimeOut := 90000;
  StatusBar1.SimpleText := ´Conectado´;
end;

procedure TForm1.NMStrmServ1Status(Sender: TComponent; Status: String);
begin
  If StatusBar1 <> nil then
    StatusBar1.SimpleText := status;
end;

end.


Obrigado...Rodrigo


Rodrigo_koga

Rodrigo_koga

Responder

Posts

02/09/2003

Allen74

rodrigo,

Qual foi o erro retornado pelo windows?

Neste caso não seria melhor transmitir o pacote via FTP ao invés de utilizar um StreamServer?


Responder

Gostei + 0

02/09/2003

Rodrigo_koga

Encontrei um erro quando ele chega para enviar proximo dos 8000 pacotes, sera q pode por causa da quant ou um tipo de estouro no array.
Pode ser por FTP, mas naum se viabiliza o envio de a atualizacao do lado do cliente, vc tem algum exemplo por FTP?
Obrigado...Rodrigo


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar