[id] = CreateUDPObject(id[, port, ip$, mode, protocol])
port
can be used to specify at which local port the UDP object should be
created. If you do not specify this argument, CreateUDPObject()
will
choose a vacant port automatically, and you can use GetLocalPort() later
to find out the port number of the UDP object. In the first argument,
you need to pass an identifier which is needed to refer to this UDP object
later on. Alternatively, you can pass Nil as the first argument. In that
case, CreateUDPObject()
will select an identifier automatically and
return it to you.
Starting with Hollywood 8.0 there is a new mode
argument which allows you
to specify the type of UDP object that should be created for you. This can
be one of the following predefined values:
#UDPSERVER:
ip$
can be used
to specify a local IP address the UDP object 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. #UDPSERVER
is the default mode for CreateUDPObject()
.
#UDPCLIENT:
ip$
and port
must be specified to specify the server the client should be connected to. If your
UDP object always sends data to the same server, it is recommended to create it as
a #UDPCLIENT
object because SendUDPData() is faster then. (V8.0)
#UDPNONE:
ip$
and
port
are ignored. Unconnected UDP objects are useful if you need to send data to
different servers without being able to receive data on your own. (V8.0)
Additionally, Hollywood 8.0 introduces an optional new protocol
argument
which allows you to specify the Internet protocol that should be used by the
UDP object. 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 UDP object is created, you can use the commands SendUDPData(), ReceiveUDPData(), and the OnReceiveUDPData event handler to communicate with other systems in the network.
Please note that UDP is an unreliable transfer protocol. It is faster than the TCP protocol but data may arrive incompletely or out of order. Thus, it is only suitable for purposes that do not depend on the integrity of the transferred data.
#UDPCLIENT
#UDPSERVER
) or to
connect UDP object to (for #UDPCLIENT
) (defaults to "*" for #UDPSERVER
); must
be set for #UDPCLIENT