Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Indy TCPClient and OnDisconnect event

Status
Not open for further replies.

McGregor80

Programmer
May 15, 2005
13
PL
Hallo

I have problem with this event becouse there is no reaction when i shot down the serwer. I expected some action but it seems there is nothing going on.

I even tried to set timer for constant checking if connected property is false/true.:
if(TCPClient->connected==false)
ShowMessage("server closed");
but there is no effect.

what is reason for this? I think there is some other way to check if it's still connected or not?

Meybe when i shotdown server i should disconnect all incoming connections? But what when server just "abnormal terminate" himself or else?

How easy check client connection state?

Help. Thanks
 
You will get an error message when your program tries to send something through the socket. When I programmed a tiny client-server application I resolved the issue by sending every few seconds a control string to the server, (something like IRC protocol's "PING") and waiting for acknowledgment.
Of course, that's a resolution for abnormal termination. For normal server shutdown it's enough to inform all connected clients about shutdown and then close the connections.

At least, that's how I did it. I worked with Indy sockets once or twice, so maybe there are better ways.

Mike
 
You are right. I should make disconnect in server when i switch it off but every connection has separate thread.

So when i work inside some event ex: onServerRead i do:
AThread->Connection->what ever i want to do with this client. ReadLn()

How to do it outside AThred?

Is there any option to disconnect every connected client?

I'm not to good in threads so don't know how to do it.

Thanks for help
 
I think you got a list of active connections.
you can iterate through the list and send each
connection a message and then shut down.

I got this from a chat program I codded using
TServerSocket. mabe indy is similiar

Code:
 for (int y = 0; y < (ServerSocket->Socket->ActiveConnections); y++)
                ServerSocket->Socket->Connections[y]->SendText(CHAT + Str1);

tomcruz.net
 
Thanks Guys.

I've tried different ways(excluding period message send test by client-it's doing to much trafic on LAN).
I've even made Handle connection[n] for every connected client and tried to disconnect client with connection[1]->Disconnect(); but it seems that indy didn't good with this.
It just doesn't work.

Even when i placed timer in client and checked if(connected==true) it didn't work.

Also after i set CheckForGracefullDisconnect(true,true);
CheckForDisconnect(true) it didn't help.

I realy don't know how to do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top