UDP Server&Client

Navigation:  Widget Designer > Devices >

UDP Server&Client

prev main next

Navigation:  Widget Designer > Devices >

UDP Server&Client

prev main next

Please wait. Due to its content this page might take a while to load...

The UDP Server&Client in the Configuration dialog allows to easily create a UDP connection. The UDP Server&Client connection is perfect if you like to listen on a certain port and optionally send messages to various addresses. The UDP Client however is more useful for scenarios where you like send UDP messages to a fixed address and optionally also receive messages. The port is scriptable which allows you to use the UDP Server&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 Server&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.

Adding a New UDP Client

To add a UDP Server&Client, open the Devices menu and select "UDP Server/Client > Create UDP Server/Client". This opens the Configuration dialog. Alternatively, you can add a new UDP Server/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 Server/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 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.

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.

Using the Connection in Regular Scripting

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_Server_Client1.Send("",55550,"This is my time: " + Now")

Displaying incoming messages is also easy:
vstring = Udp_Server_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.

Using the Connection with Event Listeners

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. please see the chapter Event Listener for a detailed description of its functionality and UDP Client Events for an overview (with examples and description) of the available events.