Welcome, Guest
Guest Settings
Help

Thread: Crashed at TIdUDPClient ReceiveBuffer() if UDP server side not running.


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Feb 17, 2017 6:22 PM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
GAI CHEW KAI

Posts: 115
Registered: 7/25/14
Crashed at TIdUDPClient ReceiveBuffer() if UDP server side not running.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 16, 2017 6:37 PM
Embarcadero® C++Builder XE8 Version 22.0.19027.8951
Android 6.0.1.
Windows 10 Pro x64, 10.0.14393.

I found out the application built for mobile android, if the UDP server side is not connected, once
executed __foo() below for the second time, the app crashed at ReceiveBuffer().

void __foo (void)
{
....
udp->ReceiveBuffer( idbUDPRead, 512 );
....
udp->SendBuffer( idbUDPWrite );
....
}

The try catch statement cannot capture any violation here.

This situation only applied to Android platform, the Windows desktop platform is running fine, no crash and when the UDP server is up and running, the Windows desktop's __foo() where both ReceiveBuffer() and SendBuffer() were working fine

Please advise.
Remy Lebeau (Te...


Posts: 7,500
Registered: 12/23/01
Re: Crashed at TIdUDPClient ReceiveBuffer() if UDP server side not running.[Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 17, 2017 6:22 PM   in response to: GAI CHEW KAI in response to: GAI CHEW KAI
GAI wrote:

I found out the application built for mobile android, *if the UDP
server side is not connected*, once executed __foo() below
for the second time, the app crashed at ReceiveBuffer().

Crashed how exactly?

UDP has no concept of connections. If the server is not online, there will
simply be nothing to read, and sends will just go into oblivion.

You are calling the version of ReceiveBuffer() with a timeout parameter,
and you are setting that timeout to 512ms. If no data arrives in 512ms,
ReceiveBuffer() will simply return 0 bytes.

If you attempt to send data to a peer while is offline, the network will
usually send back an ICMP "destination unreachable" packet in reply. *IF
AND ONLY IF* you use TIdUDPClient.Connect() to associate the UDP client with
that specific peer IP/Port (causing Indy to use the send() and recv() socket
functions instead of the sendto() and recvfrom() functions), then the OS
will take note that the ICMP packet was received and cause subsequent recv()/send()
operations on the same socket to fail with a suitable error code. Which
in turn will cause Indy to raise a suitable exception to your code.

The try catch statement cannot capture any violation here.

What are you trying to catch exactly? Please show your actual code.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02