Avisaro Online Documentation - Wiki
Impressum Kontakt Sitemap

CONNECT

Description

CONNECT actively opens a TCP connection. It needs four arguments which are described below:

1. A handle number
This can be any number in the range from 100..199. Those values are reserved for TCP connections. If CONNECT succeeds, the given handle must be used in subsequent invocations of data tranfer commands on this connection.

2. The remote IP address
This is a 32 bit signed integer number that is the IP address of the remote station. To calculate that number from standard dotted notation, use the RESOLV function.

3. The remote port number
This is the port where the remote service is listening. Although this is also a 32 bit number, only the lower 16 bits (0...65535) are used.

4. A TX delay value
This value is only used when the connection is used for "streaming mode". While streaming, data is collected until TX delay time-out or the transmit buffer is full.

CONNECT sets LASTERR accordingly to:

0 (ERR_OK)
if everything woks

4 (ERR_ARGUMENT)
if one of the arguments was wrong

38 (ERR_NOCONN)
if, for any reason, a connection could not be established

39 (ERR_NET_DOWN)
if the network interface is not active

32 (ERR_FILE_OPEN)
if the given handle is already in use

26 (ERR_FIL_EXHAUSTED)
if the system has too few ressources

Example

This little program tries to connect to the Avisaro web site on port 80 (HTTP). It uses predefined handle #101 and waits in a loop until the connection is established. Then it prints a message and closes the connection.

outmode -2
connect 101, resolv ("http://www.avisaro.com"), 80, 0 print LASTERR REM wait for connection while status(101) <> 9 wend print "CONNECTED!!!" close 101

Remarks

CONNECT is only functional on modules that have a kind of network interface (WLAN or Ethernet). Any open socket must later be closed, using the CLOSE command, to free up resources. This must also be done if the remote station already has finished the connection. If the script ends, open sockets are not closed automatically.