OpenConnection -- connect to a server (V5.0)
[id] = OpenConnection(id, server$, port[, table])
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 an 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 you will have to specify "" 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:

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:

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

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 the adapter set using SetDefaultAdapter(). See Loaders and adapters for details. (V8.0)

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)

This tag can be used to specify additional data that should be passed to network adapters. If you use this tag, you must set it to a table of key-value pairs that contain the additional data that should be passed to plugins. See User tags for details. (V10.0)

identifier for the new connection or Nil for auto id selection
server to connect to
port to connect at
optional: table argument containing further options (see above) (V8.0)
optional: identifier of the new connection; this will only be returned when you pass Nil as argument 1 (see above)
OpenConnection(1, "", 80)
SendData(1, "GET " ..
a$ = ReceiveData(1, #RECEIVEALL)
The code above connects to and downloads the index HTML page.

Show TOC