LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it it possible to check if a UDP port is already in use?

Hi all,


I have a UDP stream set up between a piece of Labview code I wrote and a program provided by another company, where Labview is on the receiving end. Its ok if a few packets are lost here and there (I realize this can happen with the UDP protocol), but I want to make sure that the information I'm receiving isn't coming from an unexpected source.

 

Is there anyway to make sure that a UDP port isn't already in use?

 

Also, if another program was reading packets on the same UDP port as my Labview code, would they both receive every packet sent to that port? Or is only one of the programs allowed to receive the packet, and the other would never see it (race condition)?

 

Thanks!

0 Kudos
Message 1 of 2
(3,210 Views)

UDP is a sessionless protocol, meaning that anyone listening on the specified port CAN receive the data. CAN because as you noted there is no guarantee in the protocol that it will be received. And if you send the data not to a specific address but a multicast address not only one computer can receive it but in fact every computer on the same subnet listening to that multicast address and depending on the TTL of the packet also computers in neighbouring subnets, although that last one is not a very reliable operation since routers can be configured to drop multicast packages anyhow despite of a different TTL saying otherwise.

 

Accordingly there is no real way to make sure that a receiving UDP port is not already in use, since you don't build up a connection. UDP is more or less analogous to shouting your messages through a megaphone, and anyone listening on the right frequency (port) can hear it. You do bind the sender socket to a specific port number but that makes little difference.

Rolf Kalbermatter
My Blog
Message 2 of 2
(3,195 Views)