[id] = CreateServer(id[, port, ip$, backlog, protocol])
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
an 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 "127.0.0.1"
(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:
#IPV4:
#IPV6:
#IPV6
is currently unsupported on AmigaOS and compatible systems.
#IPAUTO:
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.