Article View: borland.public.cppbuilder.internet.socket
Article #3579How to reconnect a client ?
From: Denis
Date: Tue, 28 Jun 2005 13:58
Date: Tue, 28 Jun 2005 13:58
65 lines
2944 bytes
2944 bytes
Hello, I'm sorry if it is a little long...
Can anybody say me if I'm correct using sockets. I must explain a little
what append:
I'm using many non-bloquing application with TServerSocket and
TClientSocket.
There is many executable who are both client and servers. It's a normal way
to start an application, use some features and close the application.
At time 't' an application is server with 'n' client connected. In the same
time this application is also a client connected to one or more servers.
My question: What exactly must i do when a client connection is broken ? The
socket is unusable and unable to reconnect to the server.
So I must delete it and create a new client socket to lookup again the
server.
What is the right way, and the order, to process ??
This a part of code that do actually this. ( this a client part ) is it
correct ?
void __fastcall client::ServerError(TObject *Sender, TCustomWinSocket
*Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
TClientSocket * err_socket = (TClientSocket * )Sender;
// On ferme le socket pour provoquer un evenement Disconnect et liberer
la m๏ฟฝmoire
err_socket->Close();
// close immediately call OnDisconnect event
Socket->Close();
// free memory ?
delete err_socket;
// all done ?
ErrorCode = 0;
}
void __fastcall client::ServerDisconnect (TObject *Sender, TCustomWinSocket
*Socket)
{
TClientSocket * err_socket = (TClientSocket * )Sender;
// create a new connection socket
TClientSocket * new_socket = new TClientSocket (NULL);
new_socket->ClientType = ctNonBlocking;
new_socket->OnConnect = ServerConnect;
new_socket->OnDisconnect = ServerDisconnect;
new_socket->OnError = ServerError;
new_socket->OnLookup = ServerLookup;
new_socket->OnRead = ServerRead;
new_socket->Host = err_socket->Host;
new_socket->Port = err_socket->Port;
new_socket->FreeOnRelease();
// Active this new connection
new_socket->Active = true;
}
Thanks in advance,
-Denis
Technical Details
Message-ID:
<42c15771@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,274cba0e00c4db70,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII Reply-To: "Denis" <d.martinez@lac-sofreltc.fr> From: "Denis" <d.martinez@lac-sofreltc.fr> Newsgroups: borland.public.cppbuilder.internet.socket Subject: How to reconnect a client ? Date: Tue, 28 Jun 2005 15:58:08 +0200 Lines: 67 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 81.80.234.43 Message-ID: <42c15771@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1119967089 81.80.234.43 (28 Jun 2005 06:58:09 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail