LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send UDP packets to an URL

Hi all,
my CVI application has to send UDP packets to a host over the internet. I found the free available UDP.fp on the NI website and in general this works fine.
 
The problem is, that the UDPWrite() function only accepts the address of the target machine as integer, means I need to know the correct IP. Unfortunateley the IP of the target machine is dynamically assigned and changes from time to time. So I would prefer to use an URL instead.
 
Is there a known function to get the IP from an URL like it is available in LabVIEW  with the "String To IP"?
 
Thanks for any help!
0 Kudos
Message 1 of 4
(4,275 Views)

I have not seen a direct function to resolve a url name to an IP address withing CVI.  I can think of a couple of options if you do not want to use TCP for your application:
If the target will accept a tcp connection you could establish a link using ConnectToTCPServer() and then use GetHostTCPSocketHandle() and get the IP from the socket structure.  You could then kill the TCP link and use the IP for your UDP socket connection.

Another option would be to implement a DomainNameServer (DNS) query directly using UDP.  DNS is a UDP based protocol, so it should be very practical to do a DNS lookup directly from UDP.  I have never needed to do this, but there may be sample code for an implementation available on the internet. 

There are also windows SDK functions that can be used to access DNS lookup.  If you have the CVI FDS and are comfortable with the MSDN web site, that is another route to take.

0 Kudos
Message 2 of 4
(4,255 Views)

I looked a little bit into UDP.fp which is based on winsock. I also found an example in MSDN that does directly what i needed. The link is here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/gethostbyname_2.asp

With this knowledge I extended the UDP.fp accordingly and it works fine.

The only thing to know is that you have to open the winsock library first using WSAStartup() before you can resolve a URL name to an IP address. This was done in UDP.fp during the UDPOpen() call. I have separated this to allow DNS lookups before opening the actual socket.

If you are interested in my modified UDP.fp, please let me know.

0 Kudos
Message 3 of 4
(4,235 Views)
That looks like a good solution.  Thanks for comming back and posting the results.
0 Kudos
Message 4 of 4
(4,227 Views)