1

I want to write a program to monitor a network with 80 devices that they have IPs. I am Delphi programmer. It doesn't matter to use Indy or ICS or any other libraries. I want check these devices by pinging (TIdIcmpClient or TPing). I just thinking about writing threads to check each device separately. But in this post Delphi (XE2) Indy (10) Multithread Ping an expert which himself is in Indy project (Remy Lebeau) said in his answer that windows itself is suffering from multiple instances interfering with each others' replies. He suggested to use one socket thread and the other threads use this thread for pinging. but I think in this case it is same as writing this checking in serial and maybe it is better to write it in serial, because it doesn't need to check critical section. My question is, can't we use any way to ping multiple devices with dependent threads? does Linux have same problem like windows that Remy Lebeau mentioned?

I just wondering why the responses from multiple instances may interfere each other. does ICMP encapsulated in IP or not (ICMP_Packet)? if it does why can't we understand from what source this reply is coming? if we can see the source why we may mistaken the response?(if you see the link about the ICMP packet in the follow you see an example that the ping command resulted with responses that the IP is obvious on them.) there is another thing. who process this ICMP? I mean when someone ping another device, that device how reply to the ping request? there are listeners or what? and when the device ping the other who is waiting for response? ping is a request or not? if not what is it? and the last thing. How can I forge my own ping request by making the packet and trace it?

so many question. I am confused.

Answer: Yes. but if you want use 3rd-party components don't use Indy. It has problem in it's core. use ICS. You can find OverbyteIcsPingTst.dproj in the demos of this open-source pack of components. btw the answer that is given in Delphi (XE2) Indy (10) Multithread Ping and accepted by the person who asked this question is not work well! because it uses the Indy and the writer of the code himself in DoPing function of his code commented that:

//We will send here, but if we have recently sent some Pings, we may receive 
//a response to a previous Ping and not get a response to our particular Ping

so this unit because using of Indy can not be use if it is important for you to have a true response!

Community
  • 1
  • 1
Loghman
  • 1,500
  • 1
  • 14
  • 30
  • 1
    "so many questions" Exactly. This is QA site - each "article" is one question - one answer. So i think you should first go into some Windows forum and ask questions about Windows TCP/IP stack implementation details. Or maybe do it in any Windows StackExchange site (but remembering "1 article = 1 question" rule). Then, after you would know how TCP/IP works in Windows, you would start to implement it in Delphi and welcome back. As of now... StackOverflow is not a forum, it is a very specific place for short exchanges with very narrowly defined topic – Arioch 'The Oct 29 '13 at 07:26
  • @Arioch'The : my exact question is the title. all of these questions are chained together. I actually know some of the answers. I asked these questions to mention that with knowledge of knowing that ICMP is encapsulated in IP. why in Multi-threading we may get not acceptable result. at last I said that I am confused because I see some paradox. I am not a beginner and wrote many TCP and UDP App in delphi, so you misunderstood about my question. And I don't see any reason that why U add tcp-ip tag!!! :| – Loghman Oct 29 '13 at 07:51
  • "why the responses from multiple instances may interfere each other" and whether they do or not - is the question about operating system implementation details. Does Windows allow MT ICMP or not ? Does Linux allow MT ICMP or not ? All those questions are a level deeper than Delphi or any other application language. "all of these questions are chained together" but they still are questions. "I actually know some of the answers" then remove those questions and put facts ("answers") instead. – Arioch 'The Oct 29 '13 at 08:06
  • I find it hard to believe the the system cannot support multiple ICMP requests. But I know nothing about networking! – David Heffernan Oct 29 '13 at 08:13
  • @DavidHeffernan read the SO article linked in question (actually i cannot understand why this question is not a duplicate of it). That is not a problem of multithreading but rather a problem of async communications and properly matching challenges with responses. At least in Indy. – Arioch 'The Oct 29 '13 at 08:20
  • Remy explains that you need to modify the indy code so that you have multiple sender threads and only one receiver thread. At the moment, there is a sender thread and receiver thread per IdICMP component. So if you have multiple components you will have more than one receiver thread and that is the problem. – whosrdaddy Oct 29 '13 at 08:47
  • @whosrdaddy Remy in his answer said that windows itself suffer from the same problem and said exactly: " If you open multiple command-prompt windows and run Windows' "ping" utility, it can also suffer from multiple instances interferring with each other's replies." to be honset I myself opened 5 command-prompt and at least 10 min watching the responses. but I didn't see any interfering. maybe I didn't watch well. in my opinion there is no reason they interfere each other. and ICMP possibly work fine with multi-thread. I asked the question to understand what the other people know about this. – Loghman Oct 29 '13 at 09:42
  • I don't know if Remy is correct in stating that windows PING suffer from the same problem. All I know is that IdICMP will not work from multiple threads for reasons that Remy explained. You can use Darian Miller's solution in the linked SO post. – whosrdaddy Oct 29 '13 at 10:18
  • @whosrdaddy I see the code that U mentioned. Darian Miller in his DoPing function wrote a comment that is: "//Indy's core problem... //We will send here, but if we have recently sent some Pings, we may receive //a response to a previous Ping and not get a response to our particular Ping." you see that miller said that, it's Indy's problem, and not said that is windows problem. If I could become sure that the problem is Indy not windows or ICMP it would be nice :D I am trying to write something in ICS(Internet Component Suite) now. but how can I be sure that code working well all times? – Loghman Oct 29 '13 at 10:33
  • There are many mulitping tools out there, so there is no 'windows' problem. Maybe the PING application has a problem but that's another story. Maybe ICS suffers from the same problem, you'll have to take a look at the source code. You can contact the writer of the ICS suite (François Piette) if you want to be sure. http://www.overbyte.be/frame_index.html?redirTo=/author/ – whosrdaddy Oct 29 '13 at 10:43
  • @whosrdaddy You are right. I must contact ICS's writer. – Loghman Oct 29 '13 at 10:45
  • I put the multiple ping scenario to the test too, at different times, started 6 different CMD windows pinging different websites - observed absolutely no interference between them. The only interference I could imagine is the NIC, but surely the NIC can handle much, much more than 6 concurrent pings. – Jerry Dodge Oct 29 '13 at 12:43
  • 1
    Windows itself can inspect packets and send them to the same processes that requested them. You could do something similar. – Marcus Adams Oct 29 '13 at 13:46

0 Answers0