
This chapter describes how to open and manage a TCP connection using the BASIC scripting. For example, an external sensor only sends data but can't be modified to send commands to handle a connection.
See (
here) to get details on how open and manage a TCP connection unsing commands send from an external device such as a micro controller.
This document assumes you are familiar with TCP/IP fundamentals. For further information on TCP/IP please search the internet or follow the external links:
A TCP connection can be established two ways:
1.) Waiting for a incoming connection (Avisaro is TCP server)
Use the command "LISTEN" (more) to create a 'TCP socket' in listen mode. Specify an internal 'handle' number - this handle number adresses this TCP socket. Also specify a TCP port number.
2.) Connection to a server (Avisaro is TCP client)
Use the text command "CONNECT" (more) to actively connect to a TCP server. Specify an internal 'handle' number, the other TCP adress and port number.
Once the TCP socket with its handle number is declared, you can query the module whether the TCP connection was established successfully:
Using the "STATUS" command (
more) it can be verified whether or not a connection was established. A return value of '9' for example means a successfully established connection.
Once the connection is established, data can be exchanged using the "PUT" (
more) and "GET" (
more) command. One TCP packet can hold 1452 bytes of data. Ideally, an array with this length should be used for sending and receiving data.
Sending data with PUT
The PUT command is used to send data. The handle number specifies which connection to use since more than one TCP connection can be handled. As data to send, a string variable or an array can be given as a parameter. Remember to check the dummy variable 'LASTERR' after sending since transmitting data can fail. See command describtion for details (
more).
Receiving data with GET
The GET command is used to receive data. It is advised to define an array with 1500 Bytes as the receiving array - otherwise a received tcp/ip packet does not fit. See command details (
more).
When done with sending or receiving data, the connection can be closed. Use the "CLOSE" (
more) command to perform this function.
While receiving and transmitting data, the TCP/IP connection can be interrupted. Reasons could be the loss of wireless conenction or the other party was switched of or terminated. The command "STATUS" (
more) allows to monitor the connection and reaction properly to a change in connection status.
Even embedded systems can connect to a server in the Internet. This example shows how to connect to google using Scripting:
' HTTP Get Beispiel |
Header information Sets variables to |