Aurora Visio Studio TOP » Tutorial Exercises » TCP/IP: Shoutbox Client (tcpip_shoutbox_client)
TCP/IP: Shoutbox Client (tcpip_shoutbox_client)
Aim
Create a TCP client which connects to a server and sends text messages typed by the user in the HMI.
Input
The input is the text message typed by the user in the HMI.
Output
The client should connect to the server and send the typed message whenever the user clicks a "Send" button.
The client should disconnect and close when the user clicks an "Exit" button.
Hints
Use the TcpIp_Connect filter to connect to the server.
Create an "Exit" button in the HMI (with ImpulseButton control) and connect it to the Repeat filter in such a way, that the loop breaks when the button is pressed.
Add another button, "Send" to send text messages only on a user request. Use the Empty formula filter to create a conditional String (a copy of the text-box content) only when the button is pressed.
Labeling connections is explained in this article.
You can learn how to turn on sections here.
Solution (AVS)
-
Make sure that you have the server application already created.
-
Turn on sections.
-
Add the TcpIp_Connect filter to the INITIALIZE section and configure its inPort input.
-
Add the TcpIp_WriteText filter in the PROCESS section.
-
Create an HMI with one TextBox and two ImpulseButton controls. Name the buttons "Send" and "Exit" in the Properties window.
-
Go back to the Program Editor and add the Formula filter. Create two inputs:
-
Create an output Text of String? type:
Text = if inSend then inHMIText else Nil
-
Connect the Text output from the formula to the inText input, so that the latter filter is executed only when the button is pressed.
-
To create a loop that breaks when the "Exit" button is pressed, add the Repeat filter and connect it with the outValue of the "Exit" button.
-
Add the DelayByPeriod filter to suspend the program workflow for inTime milliseconds relative to the end of the filter's last invoke time.
-
Add the TcpIp_Close filter in the FINALIZE section to close the connection on exit.
その他の資料
- TCP/IP Networking - Detailed information about using TCP/IP filters.