Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Apr : Connection lost due to "connection reset by peer"-error

www.cryer.info
Managed Newsgroup Archive

Connection lost due to "connection reset by peer"-error

Subject:Connection lost due to "connection reset by peer"-error
Posted by:"Shiva" (shi..@gonzo.com)
Date:Sun, 23 Apr 2006 18:20:02

Hi,

I'm writing a program that intercepts and manipulates certain newsgroups
messages. It acts as a "gateway" between a client like Outlook Express (OE)
and the newsserver of the ISP.
The (current test-)program has a TIdTCPServer component and is being tested
with OE. It works well, but OE causes an "connection reset by peer"
exception if the user tries to refresh the headers of a newsgroup and
suddenly moves to another newsgroup while OE had not finished receiving all
the headers.
The exception causes the server-client connection to be disconnected (?).
But now the problem: OE does not reestablish a connection! OE displays the
message "The TCP/IP connection was unexpectedly terminated by the server"
and still assumes the connection to be open/connected?
My own ISP-newsserver is able to handle this, so there must be a solution!

Here's the source of my test-program:

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 }
    fStartStr: string;
    fConnect: boolean;
    fREady: boolean;
    procedure LogMessage(aMess: string);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.IdTCPServer1Connect(AThread: TIdPeerThread);

begin
  self.IdTCPClient1.Connect;
  fStartStr := self.IdTCPClient1.ReadLn;
end;

procedure TForm1.IdTCPServer1Exception(AThread: TIdPeerThread;
  AException: Exception);
  var f: textfile;
begin
  LogMessage('Error='+ AException.Message);
end;

procedure TForm1.IdTCPServer1Disconnect(AThread: TIdPeerThread);
begin
  showmessage('Disconnect');
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  f: textfile;
begin
  assignfile(f, 'c:\test.txt');
  rewrite(f);
  closefile(f);

  self.IdTCPServer1.OnExecute := pdmsExec;
  fStartStr := '';
  fConnect := true;
  fReady := false;
  self.IdTCPServer1.Active := true;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
IdTCPServer1.Active := false;
end;

procedure TForm1.PdmsExec(AThread: TIdPeerThread);
Var Command, RespPlanet: string;
begin
  // wait till telnet connection has received data

  //while not fReady  do sleep(1);

  if fConnect then begin
    fConnect := false;
    AThread.Connection.WriteLn(fStartStr);
    LogMessage('Connect='+ fStartStr);
  end
  else 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;
end;


procedure TForm1.LogMessage(aMess: string);
var
  f: textfile;

begin
    assignfile(f, 'c:\test.txt');
    append(f);
    writeln(f, aMess);
    closefile(f);
end;


I'd be thankful if anyone could help me!

Replies:

www.cryer.info
Managed Newsgroup Archive