I'm using Indy10 to connect to a custom made ESP32 based WiFi camera.
...
Everything is working fine, but I have to use a TIdIcmpClient to check that the camera server is online before using Client.Connect or it crashes.
Crashes how, exactly?
TIdTCPClient.Connect() raises an exception if it can't connect to the server. That is not a
crash, unless your code is not handling the exception properly.
ICMP will tell you only whether the device is reachable on the network. It will not tell you if the device has a running TCP server that can be connected to. You still have to call
TIdTCPClient.Connect() regardless. So, your best option is to simply wrap the
TIdTCPClient.Connect() call in a
try..except block to catch the exception, and then move on with your code logic as needed.
The problem in Linux is that TIdICMPClient requires root access and I don't want that .
Known issue:
https://github.com/IndySockets/Indy/issues/122The workaround is to use ICMP over a SOCK_DGRAM socket, which does not require root access, rather than a SOCK_RAW socket:
Unprivileged ICMP sockets on Linux.
ICMP sockets (linux)Indy doesn't have any high-level components that allow you to create such a socket (all uses of
SOCK_DGRAM are limited to
IPPROTO_UDP), but you can probably cobble something together using Indy's
TIdSocketHandle and/or
TIdStack... classes directly.
Also, there are caveats with this DGRAM+ICMP approach, ie:
- only ICMP echo requests are supported
- may not be implemented uniformly across different Linux distributions
- ports are used as message identifiers
- may require a call to
sysctl to enable:
https://lkml.org/lkml/2011/5/18/305