Board index » delphi » Socket error 10054 Connection reset by peer

Socket error 10054 Connection reset by peer

I use Indy 8.007b on a Delphi5 Telnet server application, where a
wireless handheld PC is used as terminal-emulation client.

Sometimes the server application crashes with
"Socket error 10054 Connection reset by peer"

I think it has to do with the user walking too far away from the RF
control station, so connetion is lost in the middle of a transfer.

Any ideas ?

 

Re:Socket error 10054 Connection reset by peer


Quote
> I use Indy 8.007b on a Delphi5 Telnet server application, where a
> wireless handheld PC is used as terminal-emulation client.

> Sometimes the server application crashes with
> "Socket error 10054 Connection reset by peer"

> I think it has to do with the user walking too far away from the RF
> control station, so connetion is lost in the middle of a transfer.

> Any ideas ?

update Indy.

Ernst Gerlach
ernst.gerl...@epost.de
http://www.gerlach-mtl.de

Re:Socket error 10054 Connection reset by peer


Quote
>> I use Indy 8.007b on a Delphi5 Telnet server application, where a
>> wireless handheld PC is used as terminal-emulation client.

>> Sometimes the server application crashes with
>> "Socket error 10054 Connection reset by peer"

>> I think it has to do with the user walking too far away from the RF
>> control station, so connetion is lost in the middle of a transfer.

>> Any ideas ?

>update Indy.

>Ernst Gerlach

So it's known problem, which is solved in 8.009b ? Are you sure ?

Re:Socket error 10054 Connection reset by peer


Quote
>So it's known problem, which is solved in 8.009b ? Are you sure ?

I know am able to reproduce it (with 8.009b)
Just after a Connection.Readln(#13,2000) i disconnect my network
cables and then after a while i get the error.

But i think i found something:

procedure TForm1.IdTCPServer1Execute(AThread: TidPeerThread);
begin
  try
      With (Athread as TMvZPeerThread) do
      begin
            .......
            Connection.Write(c);
             .......
             ......
            Connection.Readln(#13,2000);
            ......
      end;
  except on e:Exception do
       memo1.lines.add(E.message);  //
  end;
end;

When the disconnect occurs dureing the readln, i get millions of
exception's  lines in my memo coming from the Connection.Write.

When removing the try except block everything seems to work fine.

Are exception still occurring (and is Indy ignoring them) or does Indy
"Need" the Socket error Exception which i am hiding ?

Re:Socket error 10054 Connection reset by peer


Question: "Why do I receive an error stating that the connection what
closed when I disconnect the network cable while receiving or sending
data?"
Answer: "Duh!"

No, really, that exception is normal: it tells you that the TCP connection
has been interrupted. You should ALWAYS trap such exception in your process
loop and dump the transaction (if applicable).

Now, for your code, there is a flaw: by catching the exception but not
stopping the process, you will actually MASK that exception and Indy will
continue to try to send data. You should either reraise the exception or
stop the transfert...

Good luck,
Stephane

Re:Socket error 10054 Connection reset by peer


Quote
>Question: "Why do I receive an error stating that the connection what
>closed when I disconnect the network cable while receiving or sending
>data?"

I did understand the error, but i didn't understand why the
application crashed. I  read somewhere "indy handles this", so
i supposed the exception was handled within the connection.read or
write methods. Just know i understand that Indy catches this out of my
Execute method in TIdPeerThread.Run. (i know, when you think about it,
it is obvious)

Quote
>Now, for your code, there is a flaw: by catching the exception but not
>stopping the process, you will actually MASK that exception and Indy will
>continue to try to send data. You should either reraise the exception or
>stop the transfert...

Ok, its clear now. In my except-block i  just added:

    if E is  EIdSocketError then Raise;

and things seem to work fine.

Thanx for spending time on my simple questions, and keep on the good
work with Indy !

Other Threads