Indy error when client is disconnected

Posted on 2004-08-23
Last Modified: 2010-04-05
When a client is forcibly disconnected, ie their internet connection drops, then millions of "Connection reset by Peer" errors are spawned. Why is this? All my code to perform functions on the socket checks whether the socket is connected before performing, so nothing should occur after this exception is occured surely? Please help, this is a time critical project. Thanks. PS also a "Connection reset by peer" error is also present in the Server app when this occurs, but it only displays one copy of this error message, then closes the debugger running the app as if nothing ever happened.
Question by:henrythacker
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 13

Expert Comment

ID: 11874176
from the Delphi help:

"Write an OnError event handler to respond to errors that arise with the socket connection. Set the ErrorCode parameter to 0 if the OnError event handler successfully deals with the error condition, to prevent an ESocketError from being raised."

Occurs when the socket fails in making, using, or shutting down a connection.

Delphi syntax:

property OnError: TSocketErrorEvent;

C++ syntax:

__property TSocketErrorEvent OnError = {read=FOnError, write=FOnError};


Write an OnError event handler to respond to errors that arise with the socket connection. Set the ErrorCode parameter to 0 if the OnError event handler successfully deals with the error condition, to prevent an ESocketError from being raised.

if you don't know exactly where the error is raising, use that to stop the exception from showing

the best way of doing it however would be to have a
try..except..end and handle any error in the Except..End part, like writing to a log file instead of showing the message to the user, also, if you are using events you need to handle the exceptions in the events as well

Author Comment

ID: 11874292
Sorry forgot to mention in the question that we are dealing with Indy sockets here in IdTCPClient and IdTCPServer components. Have tried blocking in the TRY and EXCEPT clauses around all things relating to the socket, so can't quite comprehend what is raising this error, unless it is an internal working of the socket, which is surely solveable, as Indy's own demo doesn't raise this error with the same conditions.
LVL 13

Accepted Solution

BlackTigerX earned 50 total points
ID: 11874579
do you have try..except in all your events as well? onConnected, OnStatus, etc

it happens that you have try..except in the code flow, but the code generates events, and those events generate exceptions outside your flow (and so, outside that try..except)

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 11874688
Ok, i have found out that the error is when the component is polled for messages. I have enclosed this code in a try...except.. the only trouble is, the delphi error box pops up in place of my message, and since this error reoccurs for infinity, the application just ends up crashing out. Is there any way to prevent delphi handling the message during runtime too, and to make my code in the except clause take preference?

Author Comment

ID: 11874820
Sorry silly me, just running the whole thing outside of the IDE silenced the Delphi errors, and i saw my Except code being used instead. Thanks.
LVL 13

Expert Comment

ID: 11874941
go to the Delphi Menu Tools, Debugger Options, Language Exceptions, turn off "Stop on Delphi exceptions", see if that helps you run your program from inside Delphi

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor ( Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question