Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Dhr. Kweetnie
Fri, 02 Jul 2004 10:01
Indy 9.0.14 UDP client question
Author: 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
Re: Indy 9.0.14 UDP client question
Author: Dhr. Kweetnie
Date: Fri, 02 Jul 2004 10:07
Date: Fri, 02 Jul 2004 10:07
57 lines
2903 bytes
2903 bytes
The socket error only happens when the Host is the loppback IP 127.0.0.1
"Dhr. Kweetnie" <omni@scient.net> schreef in bericht
news:40e5328f$1@newsgroups.borland.com...
> 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
>
>
Re: Indy 9.0.14 UDP client question
Author: Remy Lebeau (TeamB)
Date: Fri, 02 Jul 2004 17:56
Date: Fri, 02 Jul 2004 17:56
25 lines
1640 bytes
1640 bytes
"Dhr. Kweetnie" <omni@scient.net> wrote in message
news:40e5328f$1@newsgroups.borland.com...
> 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!
It is an exception to begin with, so yes you can catch it as an exception.
> catch( EIdSocketError& e )
Change that to this instead:
catch( const EIdException &e )
Or:
catch( const Exception &e )
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads