LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UDP port configuration.

Hello,

 

I want to realize UDP communication between a host computer (device A) and an instrument (device B), but I am confused about the configuration of the UDP module. I want to send parameters from device A to device B through UDP Write and use UDP Read to obtain the measurement on device B. I use two 'UDP open' functions, one for UDP write and another for UDP read. Since it is necessary to configure the port number for the 'UDP open' function, should I use the same port number for both 'UDP open'? Or should I use one port number for the 'UDP Open' used for sending data and a different port number for 'UDP Open' corresponding to receiving data?

0 Kudos
Message 1 of 9
(722 Views)

Have you checked the UDP examples which comes with LabVIEW?

 

George Zou
0 Kudos
Message 2 of 9
(699 Views)

It depends on a few factors.

 

First, if the instrument is something that already has fixed functionality, then you should consult the documentation for the instrument.  However, if the instrument is something that you control, you could set it up either way.  UPD connections are bi-directional, so you could use only one, but if you choose to use 2, that is fine as well.  It just depends on how you want to architect your application.

 

-Dave

0 Kudos
Message 3 of 9
(694 Views)

UDP is a connectionless protocol and in your case you can use the same local port for sending and receiving. You could even use port 0 and LabVIEW will pick a free ephemeral port.

 

Device B should be configured with a fixed service port where you send the requests from A. Properly configured, B can be set to send the response back to whatever the source port of the request was.

 

It is actually often important that UDP responses come back just with the source/destination port reversed, especially if firewalls or NAT is somewhere in between. Incoming responses on ports that did not send requests could get blocked.

0 Kudos
Message 4 of 9
(670 Views)

Yes, I have checked the simple UDP example. It seems like when I write to a port (say 5000), then when I configure the UDP Open function for reading, I need to use 5000 as well?

0 Kudos
Message 5 of 9
(639 Views)

Hi dave,

 

Thanks for your reply. I haven't got the instrument yet but I think it has fixed functionality.

0 Kudos
Message 6 of 9
(637 Views)

Hi altenbach,

 

Thanks for the clarification. I have checked the simple UDP example. It seems like when I write to a port (say 5000), then when I configure the UDP Open function for reading, I need to use 5000 as well?

 

I also tried to modify both UDP Open functions in the example 'Simple UDP'. When I set the ports of both UDP open as the same number, error 56 will occur, saying the port is already occupied. So is it correct that I need to specify different port number for both UDP open?

0 Kudos
Message 7 of 9
(630 Views)

In the Simply UDP example, when open UDP port to read, the receive port is the same as the remote port in the Sender.vi

 

George Zou
0 Kudos
Message 8 of 9
(629 Views)

For reading you need to listen on whatever port the other sends the message. UDP open specified the local port (used as source port for outgoing messages and will receive any incoming message that has it as destination port..

 

Each UDP packet has a source port and a destination port. They don't need to match. Only one connection can listed on any specific port. As I already said, you only need one connection.

0 Kudos
Message 9 of 9
(591 Views)