The output of the script will display three columns of numbers. The left most
number is the [variable server message type](#variable-server-message-types).
Here, a message type of 0 indicates that the message is the (tab delimited) list
of the values we requested. This is the only message type we'll be concerned
with in this tutorial. The two columns to the right of the message number are
the values of ```dyn.cannon.pos[0]``` and ```dyn.cannon.pos[1]```, in the order
that they were specified in the script.
```
0 55.85863854409634 24.0875895
0 60.18876556301853 25.2730495
0 64.51889258194073 26.36040950000001
0 68.84901960086293 27.34966950000001
0 73.17914661978513 28.24082950000001
```
<aid=how-the-client-works></a>
### How the Client Works
The script first gets the variable server's port number, and creates a TCP/IP connection to it.
The script then configures the variable server session, with the commands listed below, to periodically send the cannonball position with the following commands:
* **trick.var_pause()**
* **trick.var_ascii()**
* **trick.var_add("dyn.cannon.pos[0]")**
* **trick.var_add("dyn.cannon.pos[1]")**
* **trick.var_unpause()**
The [**var_pause**](#api-var-pause), and [**var_unpause**](#api-var-unpause) commands
are generally used at the beginning, and ending of variable server session configurations. [**var_pause**](#api-var-pause) tells the variable server to stop
sending data, if it is. [**var_unpause**](#api-var-unpause), tells the variable server to start sending data.
The [**var_ascii**](#api-var-ascii) command then tells the variable server to send messages using an ASCII encoding (rather than
binary).
The two [**var_add**](#api-var-add) commands add "dyn.cannon.pos[0]"
and "dyn.cannon.pos[1]" to the session variable list.
:warning: Please notice that the quotes around the variable names must be escaped with the '\' (baskslash) character.
When the [**var_unpause**](#api-var-unpause) command is executed, messages containing the values of the variables listed in the session variable list will be repeatedly created, and sent to the client.
By default, the variable server sends data every 0.1 seconds (that is, 10 hertz). This is equivalent to commanding: [**var_cycle(0.1)**](#api-var-cycle).
The script then enters a while-loop that repeatedly 1) waits for, 2) reads, and 3) prints the raw responses from the variable server. The responses are encoded in ASCII, as specified by [**var_ascii**](#api-var-ascii), and are of the following format:
Suppose we wanted to get the value of the initial angle of our cannon. We don't need to get it repeatedly, because it doesn't change. We just want to get it once, and then to repeatedly get the position data, which changes over time.
For this situation we can use the [**var_send**](#api-var-send) command, which tells the variable server to send the values specified in the session variable list immediately, regardless of whether [**var_pause**](#api-var-pause) was previously commanded.
To demonstrate how this works, let's add the following code to our script, right after the line where we sent the **var_ascii** command.
In this snippet of code, we add ```dyn.cannon.init_angle``` to the session variable list.
Then we call [**var_send**](#api-var-send) to tell the variable server to send us the value, and wait for the response by calling ```insock.readline()```. When it arrives, we print it.
Before the script adds the cannon position variables, we need to remove ```dyn.cannon.init_angle```, otherwise we'll be getting this in our messages too. We can do this in one of two ways. We can 1) call
[**var_clear**](#api-var-clear) to clear the the list, or 2) we can call [**var_remove**](#api-var-remove). Specifically we could do the following:
So, when we run the modified client, the first three lines of the output should look something like the following.
```
0 0.5235987755982988
0 0 0
0 0 0
```
The first line contains the message type ( which is zero), followed by the value of ```dyn.cannon.init_angle```. Subsequent lines contain the position data like before.
<aid=running-the-client-from-the-input-file></a>
## Running a Client From The Input File
Rather than having to start a client each and every time from the command line,
we can easily start it from the input file using the function
```trick.var_server_get_port()``` as illustrated in the following input file