Please wait. Due to its content this page might take a while to load...
The TCP Client in the Configuration dialog allows to easily connect to another TCP server. The IP and port are scriptable which allows you to use the TCP Client as an interface that connects to various devices on the fly. Incoming messages, e.g. feedback or status information can be received via Event Listeners. Messages can be sent out via scripting. Note that the TCP Client is only available in the licensed Widget Designer edition, not the Free version.
The Connection Manager offers another possibility to add TCP Clients. 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 TCP Client, open the Devices menu and select "TCP Client > Create TCP Client". This opens the Configuration dialog. Alternatively, you can add a new TCP 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 TCP Client is a filled blue circle. An empty blue circle indicates an enabled device where the IP address is not available. A filled gray circle indicates a disabled device.
Now, please enter the IP Address and Port of the remote TCP server. 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 > TCP 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 TCP 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 "Tcp_Client1"), Script Assist will offer you a list of all TCP 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:
Tcp_Client1.Send("This is my time: " + Now)
Displaying incoming messages is also easy:
vstring = Tcp_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.