Name
OpenConnection -- connect to a server (V5.0)
Synopsis
[id] = OpenConnection(id, server$, port[, table])
Function
This command can be used to establish a new connection to the server specified in server$. This can be either a host name or an IP address directly. The third argument specifies the port at which OpenConnection() should try to connect. In the first argument, you need to pass an identifier which is needed to refer to this connection later on. Alternatively, you can pass Nil as the first argument. In that case, OpenConnection() will select a vacant identifier automatically and return it to you.

Once the connection is successfully established, you can use SendData() and ReceiveData() to communicate with the server. When you are finished you should call CloseConnection() to disconnect from the server.

Please note that scheme prefixes like "http://" or "ftp://" are not part of a server name. These just specify the protocol that is used to communicate with the server. So if you want to connect http://www.airsoftsoftwair.de you will have to specify "www.airsoftsoftwair.de" as the server name and 80 as the port because 80 is the standard HTTP port. See below for an example. An exception to this rule might be the case where you use the Adapter tag to have a network adapter establish the connection. In that case, the network adapter might ask you to specify a scheme name like "http://" or "ftp://" but it really depends on the network adapter. Hollywood's inbuilt adapter doesn't support scheme prefixes and expects you to specify the IP address or the host name directly.

Starting with Hollywood 8.0, OpenConnection() accepts an optional table argument that can be used to specify further options. The following tags are currently recognized by the optional table argument:

Protocol:
This tag allows you to specify the Internet protocol that should be used when opening the connection. This can be one of the following special constants:

#IPV4:
Use Internet Protocol version 4 (IPv4). IPv4 addresses are limited to 32 bits and are represented using four numbers separated by three dots, e.g. 127.0.0.1.
#IPV6:
Use Internet Protocol version 6 (IPv6). IPv6 addresses use 128 bits and are represented by eight groups of four hexadecimal digits, e.g. 2001:0db8:85a3:0000:0000:8a2e:0370:7334. Note that #IPV6 is currently unsupported on AmigaOS and compatible systems.
#IPAUTO:
Let the host operating system determine the Internet protocol to use. You can then use GetConnectionProtocol() to find out which Internet protocol the host operating system has chosen for this server. See GetConnectionProtocol for details.

The Protocol tag defaults to the default protocol type set using SetNetworkProtocol(). By default, this is #IPV4 due to historical and portability reasons. See SetNetworkProtocol for details. (V8.0)

Adapter:
This tag allows you to specify one or more network adapters that should be asked to establish the specified connection. This must be set to a string containing the name(s) of one or more adapter(s). Defaults to default. See Loaders and adapters for details. (V8.0)

SSL:
Set this tag to True to request a connection through TLS/SSL encryption. Note that setting this tag when using Hollywood's inbuilt network adapter doesn't have any effect because Hollywood's inbuilt network adapter doesn't support TLS/SSL connections. However, there might be a network adapter provided by a plugin that supports TLS/SSL and if you set this tag to True Hollywood will forward your wish to have a TLS/SSL connection to the network adapter provided by the plugin. (V8.0)

Inputs
id
identifier for the new connection or Nil for auto id selection
server$
server to connect to
port
port to connect at
table
optional: table argument containing further options (see above) (V8.0)
Results
id
optional: identifier of the new connection; this will only be returned when you pass Nil as argument 1 (see above)
Example
OpenConnection(1, "www.airsoftsoftwair.de", 80)
SendData(1, "GET http://www.airsoftsoftwair.de/index.html " ..
            "HTTP/1.0\r\n\r\n")
a$ = ReceiveData(1, #RECEIVEALL)
Print(a$)
CloseConnection(1)
The code above connects to http://www.airsoftsoftwair.de and downloads the index HTML page.

Show TOC