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)

  1. Make sure that you have the server application already created.

  2. Turn on sections.

  3. Add the TcpIp_Connect filter to the INITIALIZE section and configure its inPort input.

  4. Add the TcpIp_WriteText filter in the PROCESS section.

  5. Connect inSocket with the outSocket.

  6. Create an HMI with one TextBox and two ImpulseButton controls. Name the buttons "Send" and "Exit" in the Properties window.

  7. Go back to the Program Editor and add the Formula filter. Create two inputs:

    • inHMIText of String type and connect output of the TextBox control to it
    • inSend of Bool type and connect with the output of the Send button
  8. Create an output Text of String? type:

    Text = if inSend then inHMIText else Nil

  9. Connect the Text output from the formula to the inText input, so that the latter filter is executed only when the button is pressed.

  10. 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.

  11. Add the DelayByPeriod filter to suspend the program workflow for inTime milliseconds relative to the end of the filter's last invoke time.

  12. Add the TcpIp_Close filter in the FINALIZE section to close the connection on exit.

その他の資料