Article View: borland.public.cppbuilder.internet.socket
Article #5661Indy 9.0.14 UDP client question
From: Dhr. Kweetnie
Date: Fri, 02 Jul 2004 10:01
Date: Fri, 02 Jul 2004 10:01
47 lines
2584 bytes
2584 bytes
I have an application that needs to test if a UDP Server is listening. If
this server is listening it will acknowledge my test message.
The current implementation uses the NetMaster UDP control which generates a
read event with -1 bytes when sending to a non-existing host failed. But I
want to use the Indy TIdUDPClient because my application already uses a
TIdTCPClient for something else and I don't like to use two different
architectures in one app.
The problem I have with the TIdUDPClient is that if I try to receive the
reply immediately after I send the test message, I get a popup message box
for socket error #10054 ("Connection reset by peer") when the server is not
present. What I expected was to catch it as an exception but this doesn't
happen. Compiling for Release or Debug does not make a difference. I just
don't get the exception!
Is there a better way to test if a server is present?
Here's the code for a minimal test app:
void __fastcall TForm3::TestButtonClick(TObject *Sender)
{
char RxBuf[64];
int RxSz = 64;
AnsiString PeerIP;
int PeerPort;
try
{
IndyUDPClient->SendBuffer( "TEST", 4 );
int Rxd = IndyUDPClient->ReceiveBuffer( RxBuf, RxSz, PeerIP,
PeerPort, 1000 );
Application->MessageBox( "Server responded", "UDP" ,MB_OK );
}
catch( EIdSocketError& e )
{
Application->MessageBox( "No Server", "UDP" ,MB_OK );
}
}
//--------------------------------------------------------------------------
-
void __fastcall TForm3::IndyUDPClientStatus(TObject *ASender,
const TIdStatus AStatus, const AnsiString AStatusText)
{
Application->MessageBox( AStatusText.c_str(), "Status" ,MB_OK );
}
Thanks, Antoon
Technical Details
Message-ID:
<40e5328f$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,2d5124ce231198c9,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Dhr. Kweetnie" <omni@scient.net> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Indy 9.0.14 UDP client question Date: Fri, 2 Jul 2004 12:01:51 +0200 Lines: 49 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 194.109.161.227 Message-ID: <40e5328f$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1088762511 194.109.161.227 (2 Jul 2004 03:01:51 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail