PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Erro no Socket.... #181259

10/09/2003

0

No codigo q eu vou enviar, o q ocorre eh quando estou enviando e uma maquina cai ele para o processo e diz q a erro na conexao...
Gostaria de uma ajuda como posso pular esse erro...

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;
Button1: TButton;
NMStrm1: TNMStrm;
NMStrmServ1: TNMStrmServ;
StatusBar1: TStatusBar;
FileListBox1: TFileListBox;
Table1: TTable;
DataSource1: TDataSource;
Table1Filial: TSmallintField;
Table1Descricao: TStringField;
Table1IP: TStringField;
Table1Envia: TStringField;
Table1Recebe: TStringField;
procedure Button1Click(Sender: TObject);
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 NMStrmServ1ConnectionFailed(Sender: TObject);
procedure NMStrmServ1ClientContact(Sender: TObject);
procedure NMStrmServ1Status(Sender: TComponent; Status: String);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
MyFStream: TFileStream;
i: integer;
begin

Table1.First;
while not Table1.Eof do
begin
FileListBox1.Update;
FileListBox1.Directory := Table1.FieldByName(´envia´).AsString;
NmStrm1.Host := Table1.FieldByName(´ip´).AsString;

if FileListBox1.Items.Count > 0 then
begin

for I := FileListBox1.Items.Count - 1 downto 0 do
begin
NmStrm1.FromName := FileListBox1.Items[I];
MyFStream := TFileStream.Create(FileListBox1.Items[I], fmOpenRead);

try
NMStrm1.PostIt(MyFStream);
finally
MyFStream.Free;
// if not DeleteFile(FileListBox1.Items[I]) then
// begin
// ShowMessage(´Erro ao apagar o arquivo: ´ + FileListBox1.Items[I]);
// end;
end;

end;

end;
Table1.Next;
end;

end;

procedure TForm1.NMStrmServ1MSG(Sender: TComponent; const sFrom: String;
strm: TStream);
var
MyFStream: TFileStream;
Filial: string;
begin

Table1.First;
try
Filial := copy(sFrom,2,2);
while not Table1.Eof do
begin
if StrToInt(Filial) <> Table1.FieldByName(´filial´).AsInteger then
begin
MyFStream := TFileStream.Create(Table1.FieldByName(´recebe´).AsString + sFrom, fmCreate);
MyFStream.CopyFrom(strm, strm.size);
end;
Table1.Next;
end;
finally
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 := ´Terminado o envio...´;
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 InputQuery(´Host invalido!´, ´Especifique um novo host:´, TmpStr) then
Begin
NMStrm1.Host := TmpStr;
Handled := TRUE;
End;
end;

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

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

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

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

end.


Rodrigo_koga

Rodrigo_koga

Responder

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

Aceitar