德尔福Indy Ping错误10040 [英] Delphi Indy Ping Error 10040
问题描述
我有一小段代码,通过ping它检查计算机是否存活。我们使用一个有40台电脑的房间,我想通过我的程序进行远程检查,这个活着是活的。
所以我用indy写了一个ping函数
函数TMainForm.Ping(const AHost:string):Boolean;
var
MyIdIcmpClient:TIdIcmpClient;
begin
结果:= True;
MyIdIcmpClient:= TIdIcmpClient.Create(nil);
MyIdIcmpClient.ReceiveTimeout:= 200;
MyIdIcmpClient.Host:= AHost;
try
MyIdIcmpClient.Ping;
Application.ProcessMessages;
除
结果:= False;
MyIdIcmpClient.Free;
退出;
结束
如果MyIdIcmpClient.ReplyStatus.ReplyStatusType<> rsEcho然后result:= False;
MyIdIcmpClient.Free;
结束
所以我已经在家里开发了我的wifi网络,一切都很好。
当我重新开始工作时,我测试过,我收到错误说
套接字错误#10040消息太长
在工作中我们有固定的IP和所有的电脑,我在相同的子网。
我试图从固定IP断开连接到当然是DHCP的WiFi,而不是在同一个子网,它只是工作正常
我已经尝试搜索互联网这个错误,如何解决它,但没有找到很多信息。
当然,我已经尝试将默认缓冲区大小更改为更大的值,但是没有更改任何我仍然在同一子网内的固定IP上出现的错误。
此外,我不知道这是否可以帮助找到解决方案,但我的代码对待异常,但在这种情况下,大约需要3-4秒提高错误,而超时设置为200毫秒。我不能等待这么长时间在每个ping。
顺便说一句,我使用delphi 2010,我认为它是indy 10.我也已经测试了XE2但是同样的错误。
任何想法
-----编辑-----
这个问题已经回答了,现在我试着让这个运行在多线程中,而且我也提出了另一个问题:
Delphi(XE2)Indy(10)多线程平台
将 PacketSize
属性设置为 24
:
function TMainForm.Ping(const AHost:string):Boolean;
var
MyIdIcmpClient:TIdIcmpClient;
begin
结果:= True;
MyIdIcmpClient:= TIdIcmpClient.Create(self);
MyIdIcmpClient.ReceiveTimeout:= 200;
MyIdIcmpClient.Host:= AHost;
MyIdIcmpClient.PacketSize:= 24;
MyIdIcmpClient.Protocol:= 1;
MyIdIcmpClient.IPVersion:= Id_IPv4;
try
MyIdIcmpClient.Ping;
// Application.ProcessMessages; //没有必要称这个!
除
结果:= False;
退出;
结束
如果MyIdIcmpClient.ReplyStatus.ReplyStatusType<> rsEcho然后result:= False;
MyIdIcmpClient.Free;
结束
I have a small piece of code that checks if a computer is alive by pinging it. We use to have a room with 40 computer and I wanna check remotely through my program which on is alive.
Therefore I wrote a little ping function using indy
function TMainForm.Ping(const AHost : string) : Boolean;
var
MyIdIcmpClient : TIdIcmpClient;
begin
Result := True;
MyIdIcmpClient := TIdIcmpClient.Create(nil);
MyIdIcmpClient.ReceiveTimeout := 200;
MyIdIcmpClient.Host := AHost;
try
MyIdIcmpClient.Ping;
Application.ProcessMessages;
except
Result := False;
MyIdIcmpClient.Free;
Exit;
end;
if MyIdIcmpClient.ReplyStatus.ReplyStatusType <> rsEcho Then result := False;
MyIdIcmpClient.Free;
end;
So I've developped that at home on my wifi network and everthing just work fine.
When I get back to work I tested and I get an error saying
Socket Errod # 10040 Message too long
At work we have fixed IPs and all the computer and I are in the same subnet.
I tried to disconnect from the fixed IP and connect to the wifi which of course is DHCP and not in the same subnet, and it is just working fine.
I have tried searching the internet for this error and how to solve it but didn't find much info.
Of course I have tried to change the default buffer size to a larger value but it didn't change anything I still get the error on the fixed IP within same subnet.
Moreover, I don't know if this can help finding a solution, but my code treats exceptions, but in that case it takes about 3-4 seconds to raise the error whereas the Timeout is set to 200 milliseconds. And I cannot wait that long over each ping.
By the way I use delphi 2010 and I think it is indy 10. I also have tested on XE2 but same error.
Any idea
----- EDIT -----
This question is answered, now I try to have this running in multithread and I have asked another question for that Delphi (XE2) Indy (10) Multithread Ping
Set the PacketSize
property to 24
:
function TMainForm.Ping(const AHost : string) : Boolean;
var
MyIdIcmpClient : TIdIcmpClient;
begin
Result := True;
MyIdIcmpClient := TIdIcmpClient.Create(self);
MyIdIcmpClient.ReceiveTimeout := 200;
MyIdIcmpClient.Host := AHost;
MyIdIcmpClient.PacketSize := 24;
MyIdIcmpClient.Protocol := 1;
MyIdIcmpClient.IPVersion := Id_IPv4;
try
MyIdIcmpClient.Ping;
// Application.ProcessMessages; // There's no need to call this!
except
Result := False;
Exit;
end;
if MyIdIcmpClient.ReplyStatus.ReplyStatusType <> rsEcho Then result := False;
MyIdIcmpClient.Free;
end;
这篇关于德尔福Indy Ping错误10040的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!