Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Apr : Re: Connection lost due to "connection reset by peer"-error
| Subject: | Re: Connection lost due to "connection reset by peer"-error |
| Posted by: | "Shiva" (shi..@gonzo.com) |
| Date: | Sun, 23 Apr 2006 21:46:23 |
Found the solution myself. I thought OE didn't create a new connection after
disconnecting it, but I was wrong. This corrected program is:
type
TForm1 = class(TForm)
IdTCPServer1: TIdTCPServer;
IdTCPClient1: TIdTCPClient;
IdThreadMgrPool1: TIdThreadMgrPool;
procedure IdTCPServer1Connect(AThread: TIdPeerThread);
procedure IdTCPServer1Exception(AThread: TIdPeerThread;
AException: Exception);
procedure IdTCPServer1Disconnect(AThread: TIdPeerThread);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PdmsExec(AThread: TIdPeerThread);
private
{ Private declarations }
procedure LogMessage(aMess: string);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);
var
fStartStr: string;
begin
IdTCPClient1.Connect;
fStartStr := self.IdTCPClient1.ReadLn;
AThread.Connection.WriteLn(fStartStr);
LogMessage('Connect='+ fStartStr);
end;
procedure TForm1.IdTCPServer1Exception(AThread: TIdPeerThread;
AException: Exception);
var f: textfile;
begin
LogMessage('Error='+ AException.Message);
end;
procedure TForm1.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
Logmessage('Disconnect');
IdTCPClient1.Disconnect;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
f: textfile;
begin
assignfile(f, 'c:\test.txt');
rewrite(f);
closefile(f);
self.IdTCPServer1.OnExecute := pdmsExec;
IdTCPServer1.Active := true;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
IdTCPServer1.Active := false;
end;
procedure TForm1.PdmsExec(AThread: TIdPeerThread);
Var Command, RespPlanet: string;
begin
Command := AThread.Connection.ReadLn;
LogMessage('command outlook='+ Command);
IdTCPClient1.WriteLn(Command);
if (Pos('ARTICLE', Command) > 0)
or (Pos('XOVER', Command) > 0) then begin
repeat
RespPlanet := IdTCPClient1.ReadLn;
LogMessage('LOOP response planet =' + RespPlanet);
if aThread.Connection.Connected
and (not athread.Stopped) then
Athread.Connection.WriteLn(RespPlanet);
until Pos('.', RespPlanet) = 1;
end
else begin
RespPlanet := IdTCPClient1.ReadLn;
LogMessage('response planet=' + RespPlanet);
Athread.Connection.WriteLn(RespPlanet);
end;
end;
procedure TForm1.LogMessage(aMess: string);
var
f: textfile;
begin
assignfile(f, 'c:\test.txt');
append(f);
writeln(f, aMess);
closefile(f);
end;
none