Please wait. Due to its content this page might take a while to load...
The UDP Client in the Configuration dialog allows to easily create a UDP connection. The UDP Client is perfect for scenarios where you like send UDP messages to a fixed address and optionally also receive messages. The UDP Server&Client connection however is more useful if you like to listen on a certain port and send messages to various addresses. The IP and ports are scriptable which allows you to use the UDP Client as an interface that connects to various devices on the fly if needed. Incoming messages can be received via Event Listeners. Messages can be sent out via scripting. Note that the UDP Client is only available in the licensed Widget Designer edition, not the Free version.
The Connection Manager offers other possibilities to add UDP connections. Those connections can also be used by the node system which allows a more advanced message handling or is more useful for streaming information.
To add a UDP Client, open the Devices menu and select "UDP Client > Create UDP Client". This opens the Configuration dialog. Alternatively, you can add a new UDP Client in the Configuration dialog with the "+" button.
On the right side you see several options:
The Name is the unique identifier for this object in WD and the general rules for naming objects apply here as well (only letters, numbers and underscore are allowed, the first symbol must be a letter).
If you like, you can change the default name to a more descriptive one. When scripting, enter the name to access available members as described further down.
The ID is currently used internally only. In upcoming versions it will be possible to use it for addressing the device.
The "Enable" check box is ticked per default. On the left side, you should later see that the icon in front of your UDP Client is a filled blue circle. An empty blue circle indicates an active connection but the used port is not available or blocked. A filled gray circle indicates a disabled device. Note that UDP is a stateless protocol and therefore has no connection status as known from the TCP protocol.
Now, please enter the Local Port, which is the source port the UDP Client listens on. In addition, this defines the sending port in case you are sending messages. If you not enter a specific port and leave "0", WD picks any free port. This is of interest if you are just sending messages, as the sending port is usually not important.
Next, enter the IP Address and Remote Port of the remote UDP server. This defines the destination of messages you are sending.
Click the "Apply" button to save any changes done here. You can also use the shortcut [Ctrl + Enter] to do so.
You can close the dialog now. The newly created connection will also be added to the Devices menu > UDP Client and can be opened from here or with Devices menu > Configuration.
After creating the connection, you can use it to send or receive messages via scripting.
To send messages to the UDP server, first create a CustomScript button or use the Macro editor or anything else with a scripting field. If you enter the device's identifier name into the script field (per default that is "Udp_Client1"), Script Assist will offer you a list of all UDP Client Members.
To send a message, choose the "Send" member. Literal text should always be enclosed in either single or double quotation marks otherwise the text is handled like a variable. You can also combine both like in the example. The global variable "Now" sends the current date and time:
Udp_Client1.Send("This is my time: " + Now)
Displaying incoming messages is also easy:
vstring = Udp_Client1.LastMessageReceived
Note that this assigns the last message any time the command is executed. If you like to assign it automatically whenever the message changes, use events instead.
Regarding any TCP or UDP connection, the Event Listener is the easiest way to handle incoming messages. Event Listeners can also be added to the Configuration dialog.