Hey all im getting "SOCKET ERROR #1" on macos using indy, this code works fine on Windows. Using FMX here. Using macOS Sonoma Firewall is turned off on the macOS host.
procedure TFrame_PingIPDomain.PingIPDomain;
begin
memOutput.Lines.Clear;
IdIcmpClient.ReceiveTimeout := Round(sbTimeout.Value);
// IdIcmpClient.PacketSize := Round(sbPacketSize.Value);
IdIcmpClient.Host := edtIPDomain.Text;
memOutput.Lines.Add('Pings:');
memOutput.Lines.Add('======================================');
var AvgTime: Double := 0.0;
var PingTimes := TList<Double>.Create;
for var I := 1 to Round(sbPingCount.Value) do
begin
IdIcmpClient.Ping();
if IdIcmpClient.ReplyStatus.ReplyStatusType = rsEcho then
begin
var RoundTripTime := IdIcmpClient.ReplyStatus.MsRoundTripTime;
PingTimes.Add(RoundTripTime);
memOutput.Lines.Add('Reply from ' + IdIcmpClient.ReplyStatus.FromIpAddress + ': time=' + RoundTripTime.ToString + 'ms');
end
else if IdIcmpClient.ReplyStatus.ReplyStatusType = rsTimeout then
memOutput.Lines.Add('Ping request timed out')
else
memOutput.Lines.Add('Ping request failed');
end;
PingTimes.Sort;
for var I := 1 to PingTimes.Count-1 do
AvgTime := AvgTime + PingTimes.Items[I];
AvgTime := AvgTime / PingTimes.Count;
memOutput.Lines.Add('======================================');
memOutput.Lines.Add('Statistics:');
memOutput.Lines.Add('======================================');
memOutput.Lines.Add('Min Time: ' + PingTimes.First.ToString + 'ms');
memOutput.Lines.Add('Max Time: ' + PingTimes.Last.ToString + 'ms');
memOutput.Lines.Add('Avg Time: ' + AvgTime.ToString + 'ms');
end;
SOCKET ERROR #1
I'm posting an answer based on the comment from @RemyLebeau:
SOCKET ERROR #1
on MacOS means that the operation was not permitted.You need to run your app with administrative rights.
TIdIcmpClient
uses a RAW socket, and most platforms restrict RAW socket usage to administrators only.So your code is fine, you just need to run your app with administrative rights.
And from @GorhinStroebel's comment, if you want to run your app with Admin Permissions on MacOS via the Terminal, you can run: