CreateServer -- open a new server (V5.0)
[id] = CreateServer(id[, port, ip$, backlog, protocol])
This command can be used to establish a new server that is ready to take incoming connections on the local host. The optional argument port can be used to specify on which port the server should be opened. If you do not specify this argument, CreateServer() will choose a vacant port automatically, and you can use GetLocalPort() later to find out the port number of the server. In the first argument, you need to pass an identifier which is needed to refer to this server later on. Alternatively, you can pass Nil as the first argument. In that case, CreateServer() will select a vacant identifier automatically and return it to you.

The optional argument ip$ can be used to specify a local IP address the server should be bound to. This defaults to "*", which means that the server will accept connections from the whole network. You can also specify "" (or "::1" in IPv6) to allow only connections from the local host. Note that passing "*", which is also the default, might trigger the firewall on some configurations.

The optional backlog argument can be used to specify the maximum number of client connections that can be added to the queue. This defaults to 32.

Starting with Hollywood 8.0 there is an optional new protocol argument which allows you to specify the Internet protocol that should be used when creating the server. 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 GetLocalProtocol() to find out which Internet protocol the host operating system has chosen for this server. See GetLocalProtocol for details.

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

Once the server has been successfully established, you must use the function InstallEventHandler() to listen to the events OnConnect, OnDisconnect, and OnReceiveData. These events will inform you whenever a new client tries to connect to your server, or when a client sends new data (i.e. commands that you need to handle) to your server.

identifier for the new server or Nil for auto id selection
optional: port to open up for this server, or 0 for automatic port selection (defaults to 0)
optional: local IP address to bind server to (defaults to "*")
optional: maximum number of connections that can be queued (defaults to 32)
optional: Internet protocol to use (see above for possible values); defaults to the protocol type set using SetNetworkProtocol() (V8.0)
optional: identifier of the new server; this will only be returned when you pass Nil as argument 1 (see above)

Show TOC