Click to See Complete Forum and Search --> : how to ping from Windows Mobile application
next1
Jul 26th, 2008, 04:44 PM
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!
petevick
Jul 27th, 2008, 03:19 AM
There is a ping class in the OpenNetCF or there is some code here (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2400163&SiteID=1) using IcmpSendEcho2 that you could translate to VB
next1
Jul 27th, 2008, 07:53 AM
Really thank you!
next1
Aug 15th, 2008, 07:22 AM
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:
<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 (http://msdn.microsoft.com/en-us/library/ms927418.aspx):
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 :confused: 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:
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!
petevick
Aug 15th, 2008, 12:38 PM
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?
next1
Aug 15th, 2008, 01:08 PM
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 (http://msdn.microsoft.com/en-us/library/ms927418.aspx): "This function sends an ICMP echo request and the call returns either immediately, if the Event parameter is non-NULL"?
Thank you Petevick!
petevick
Aug 16th, 2008, 02:51 AM
This (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2400163&SiteID=1) help?
next1
Aug 17th, 2008, 02:16 AM
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:
Imports HANDLE = System.IntPtr
<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!
next1
Aug 17th, 2008, 02:44 AM
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:
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!
next1
Aug 22nd, 2008, 07:04 AM
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:
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?
petevick
Aug 22nd, 2008, 08:36 AM
Again - how long does it take if you do it from your desktop
Generally, you are not going to beat those times
next1
Aug 22nd, 2008, 10:32 AM
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?
petevick
Aug 22nd, 2008, 03:15 PM
Hi,
how long does that code take on the desktop?
next1
Aug 23rd, 2008, 02:10 AM
Guess the problem is in my PPC, because from my PC, the code above return almost immediately (less than 1 second) :cry:
petevick
Aug 23rd, 2008, 08:43 AM
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 :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.