Results 1 to 15 of 15

Thread: how to ping from Windows Mobile application

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    how to ping from Windows Mobile application

    Hello,

    I can't find a way to ping in VB.net 2008 from Windows mobile application. There are no namespaces like My.Computer.Network and System.Net.NetworkInformation, from where I usually use Ping and PingCompleted handler. Is there any easy way to check if some IP is online?

    Thanks!

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: how to ping from Windows Mobile application

    There is a ping class in the OpenNetCF or there is some code here using IcmpSendEcho2 that you could translate to VB
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Smile Re: how to ping from Windows Mobile application

    Really thank you!
    Last edited by next1; Aug 8th, 2008 at 02:36 AM.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Question Re: how to ping from Windows Mobile application

    Hi Petevick,

    I successfully P/Invoke IcmpSendEcho2 and it's working almost perfect. But there are still two things that annoyed me. Here is the IcmpSendEcho2 DllImport:
    Code:
        <DllImport("iphlpapi.dll", SetLastError:=True)> _
        Private Shared Function IcmpSendEcho2(ByVal icmpHandle As IntPtr, _
                                              ByVal hEvent As Int32, _
                                              ByVal ApcRoutine As Int32, _
                                              ByVal ApcContext As Int32, _
                                              ByVal destinationAddress As Int32, _
                                              ByVal requestData As String, _
                                              ByVal requestSize As Int32, _
                                              ByRef requestOptions As ICMP_OPTIONS, _
                                              ByRef replyBuffer As ICMP_ECHO_REPLY, _
                                              ByVal replySize As Int32, _
                                              ByVal timeout As Int32) As Int32
    1. When the destination host is unknown or its offline, there is still too long time out using IcmpSendEcho2. Is there a way to solve it, using hEvent.. according to this:
    Code:
    This function sends an ICMP echo request and the call returns either immediately,
    if the Event parameter is non-NULL
    In my case, I use it as Int32 which is null because I don't really know how to implement it as EventHandler

    2. The time for DNS is too long if it's not in my network (it's just hang for 5-6seconds). I use this to resolve the IP address, before I start pinging:
    Code:
                    Try
                        ipEntry = Net.Dns.GetHostEntry(DestinationHost.Text)
                        destinationIP = ipEntry.AddressList(0)
                    Catch ex As Exception
                    End Try
    Can you please give me a hand in this with suggestion, or just point me in the right direction?

    Thank you!

  5. #5
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: how to ping from Windows Mobile application

    If you ping from your desktop, using command prompt, to a machine you know is offline, does it take shorter, longer or the same as your code?
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Re: how to ping from Windows Mobile application

    Well, my code is a little bit faster than cmd\ping command with the same timeout param (ping <ip> -w <timeout>). Is there a way IcmpSendEcho2 to work as it is described in MSDN: "This function sends an ICMP echo request and the call returns either immediately, if the Event parameter is non-NULL"?

    Thank you Petevick!
    Last edited by next1; Aug 15th, 2008 at 01:24 PM.

  7. #7
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: how to ping from Windows Mobile application

    This help?
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Re: how to ping from Windows Mobile application

    Hello Petevick,

    That was the first place from where I start after you point me, but this example is for IcmpSendEcho and work only with timeouts. This was the reason I start to P/Invoke IcmpSendEcho2 but hang on creating the event parameter (2nd one) till now... I just P/Invoke the CreateEvent from coredll.dll and this do the trick

    Providing the code for those who are looking for this:
    Code:
    Imports HANDLE = System.IntPtr
    Code:
        <DllImport("coredll.dll", SetLastError:=True, CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Auto)> _
        Public Shared Function CreateEvent(ByVal lpEventAttributes As HANDLE, <[In](), MarshalAs(UnmanagedType.Bool)> _
                                           ByVal bManualReset As Boolean, <[In](), MarshalAs(UnmanagedType.Bool)> _
                                           ByVal bIntialState As Boolean, <[In](), MarshalAs(UnmanagedType.BStr)> _
                                           ByVal lpName As String) As HANDLE
        End Function
    Thanks again!

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Re: how to ping from Windows Mobile application

    The only thing that annoyed me is the DNS thingy:
    The time for DNS is too long if it's not in my network. I use this to resolve the IP address, before I start pinging:
    Code:
                    Try
                        ipEntry = Net.Dns.GetHostEntry(DestinationHost.Text)
                        destinationIP = ipEntry.AddressList(0)
                    Catch ex As Exception
                    End Try
    Is there a way to reduce the time for GetHostEntry?

    Thanks!
    Last edited by next1; Aug 17th, 2008 at 03:06 AM.

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Re: how to ping from Windows Mobile application

    Quote Originally Posted by next1
    The only thing that annoyed me is the DNS thingy:
    The time for DNS is too long if it's not in my network. I use this to resolve the IP address, before I start pinging:
    Code:
                    Try
                        ipEntry = Net.Dns.GetHostEntry(DestinationHost.Text)
                        destinationIP = ipEntry.AddressList(0)
                    Catch ex As Exception
                    End Try
    Is there a way to reduce the time for GetHostEntry?

    Thanks!
    ...or use some timeout for Net.Dns.GetHostEntry

    Anyone?

  11. #11
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: how to ping from Windows Mobile application

    Again - how long does it take if you do it from your desktop

    Generally, you are not going to beat those times
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  12. #12

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Re: how to ping from Windows Mobile application

    I don't want to beat that times, just want the same times.

    From my PC: nslookup yahoo.com answer almost immediately (less then 1sek)

    From my PPC(with the code above) ~3 seconds when I try it for the first time(after program start) and ~2 seconds after the 1st time... Both (PC and PPC) are connected to same router. Any idea?

  13. #13
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: how to ping from Windows Mobile application

    Hi,
    how long does that code take on the desktop?
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  14. #14

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    9

    Re: how to ping from Windows Mobile application

    Guess the problem is in my PPC, because from my PC, the code above return almost immediately (less than 1 second)

  15. #15
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: how to ping from Windows Mobile application

    Have you tried using VXUtil from www.cam.com to see what timings they get from your device - worth a shot, as you may be chasing something unattainable
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width