LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UDP client to non-broadcasting server

I need to poll an existing UDP datagram server on a remote host. I cant seem to find example/instruction on how to do this (and Im brand new to labview). The examples I find all seem to assume the UDP server is broadcasting datagram using a known subnet and port. I need to be able to set the remote host IP and Port number and the send a single connectionless UDP datagram request out at approx 1x per second. Is the UDP reader component the correct one to use and if so, how do I set the remote host and port? Anybody have a sample the can send?
Thanks in advance. - Rich Schramm
0 Kudos
Message 1 of 11
(4,590 Views)
How much do you know about the server?

"Polling" a server typically imples that the server replies, so your problem is twofold:

(1) You need to send a correctly formed message.
(2) You need to receive and interpret the server response.

Or is it possible that you only need to send a one-way message?

(There are many UDP based servers that just swallow whatever they recive without acknowledgement. e.g. a syslog server).

Sending a UDP packet is easy:
Use "UDP open" with a free local port, a defined local port if the server requires it, or wire zero and the OS will choose a free ephemeral port.
Wire the connection ID to "UDP write", together with the remote IP and remote server port. Also wire your desired packet payload to "data in".

The attached image show a most simple UDP server that I have used in the past to check for networking problems. It listens on port 17000 and whenever a UDP packet arrives, it sends it right back to the port and IP where it came from. (The payload is typically a timestamp so the sender can calculate the roundtrip time, similar to ping). To only send packets, simply leave out the UDP read part. 🙂
Message 2 of 11
(4,580 Views)
Thanks for the reply Altenbach,

The legacy server was written many years ago in c on unix by me. It discards any input in the datagram request packet's data area and send a single response to the clients IP.
What I need is a labview client that can connect to it.

It appears that the attached image you provided implements the same server side functionality I have. What I am looking for what would a labview client look like that connects to your server? In particular how do specify in the labview client's udp control remote server IP and port number?

Thanks - Rich
0 Kudos
Message 3 of 11
(4,571 Views)
Attached is the most simple VI to send UDP packets at 1 second intervals to a server.

You specify destination port and destination address in the "UDP write" node. "UDP open" just creates a local socket that can be used to send to several hosts or destination ports.

(In a real application, you would also need to add some error checking, e.g. don't run the loop if UDP open fails, etc. Also have a look at the shipping example "UDP Sender".)

Message Edited by altenbach on 03-21-2005 02:48 PM

Message 4 of 11
(4,568 Views)
Its working! If anyone else picks this up, the only thing we added to the client shown by altenbach was to add a string indicator and a udp reader after the the sender. We hooked up the shared connection id and attach the readers output to the string indicator. Once per second we get a response from the remote server that updates the text box.
Great job, many thanks to Altenbach!
0 Kudos
Message 5 of 11
(4,549 Views)
I like UDP, it's so easy!

It seems you basically made my original client. 😉 (I misread your question and missed the point that you want to reveice a response back so I took that part out to keep it simple :().
If the server is close by, you might want to use a sub-second timeout waiting for a response and simply send a new packet. By default, it will wait up to 25 seconds, slowing your loop down whenever a packet is lost.
0 Kudos
Message 6 of 11
(4,545 Views)

This above conversation is really helpful. but my VI still doesnot seem to run. I have used the simplest udp send example by Altenbach (very new to LabView) and the server coudnot get the data. Hence I tried the last one adding a udp read after udp sent and attached a string indicator at the data out of it. still not working. Can anyone please help. I have attached a picture of my current VI. Thanks so much.

Download All
0 Kudos
Message 7 of 11
(3,698 Views)

The UDP Write function needs a server address to send the data to. Enter the IP address of your server machine into the "Server Name" string control and try again. With an empty Server Name, the String To IP function will return the localhost network address so try to send the data to your own computer. And your server is located at port 25000, isn't it?

 

That your receive VI doesn't work could mean many things. Either you got the address or port wrong so the UDP datagram is sent to a not existing server. Or the message you send is not recognized by the server and simply dropped. Or there is a firewall that disallows the connection. Since UDP is connectionless you generally do not receive any indication if the data was even received. A non existing server or a firewall in between will simply mean the data is put on the network wire and then gets lost. The UDP Write has no way to verify that there is a server on the other side accepting the data package.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 11
(3,668 Views)

Yes i have added the destination server IP onto the server name. Even after that data is not received. I guess my data packet is not correct. As in not per UDP format. Can you help me with what do I fill in the "datagram" /data in of UDP write. 

0 Kudos
Message 9 of 11
(3,657 Views)

@Sabiha wrote:

Yes i have added the destination server IP onto the server name. Even after that data is not received. I guess my data packet is not correct. As in not per UDP format. Can you help me with what do I fill in the "datagram" /data in of UDP write. 


Eeehm, no! The original writer of the UDP Server application is the first person you should ask about that. Or if it is documented you can read the manual. Otherwise the only other way to get to know what the data should be is to use a network sniffer and listen in on the communication between an existing client that works and the server. Even then it is often pretty cumbersome as you only get the raw bytes that are transmitted and have to figure out the actual message protocol with trial and error, which for more complex protocols can be a futile attempt.

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 11
(3,646 Views)