HostNetwork

Description

Creates an AGK network with this app as the controller, this app is added as the first client to the network. AGK networks are identified by name and are automatically broadcast to anyone listening on the local area network, meaning that other AGK apps on the LAN can pick up all broadcast networks, display their names to their users and allow them to choose one to join. AGK apps outside the LAN need the IP address and port of the hoster to join the network, this port will need forwarding to the host through any intervening firewall. The port value must be between 1025 and 65535, and will fail if another application is already listening on that port.

Warning, if the device hosting the network is an iOS device then the broadcasting part of this process will fail unless you get permission from Apple to send broadcast packets, see the following page to request permission https: developer.apple.com/contact/request/networking-multicast. If you do not have the permission then devices should still be able to join such a network if they have the IP address and port of the hosting device

You must also specify a client name to use to identify your client, all client names must be unique. This name will be visible to all other clients. Clients will be added to the network automatically and can be counted using GetNetworkNumClients. You can call IsNetworkActive immediately after this command to check that the network was setup successfully, once setup the network will not become inactive for a hoster.

Once connected the app becomes a client of the network, any other clients that connect to it join the network. All clients are treated equally and have a list of local variables that they can read from and write to, all clients can also read any variables on other clients on a read only basis.

Some ports are used by AGK for internal networking and should not be used by your application. Ports 5689-5692 are used to manage apps broadcast from the IDE. Ports 45631 and 45632 are used for named network connections. On IPv4 networks the network broadcast goes to all devices on the local subnet, on IPv6 networks the broadcast goes to the AGK multicast address "FF02::41:474B". If the device has both IPv4 and IPv6 IP addresses then HostNetwork will accept connections from both IPv4 and IPv6 networks.

If you specify 0 for the port then it will disable IPv4 connections, if you set portv6 to 0 then it will disable IPv6 connections. At least one must be greater than 0 or an error will be generated. If you do not specify portv6 at all then it will be set to 0. It should be safe to use the same port for both IPv4 and IPv6, but this hasn't been widely tested.

Returns an ID you can use to interact with this network.

Does not work when exported to HTML5

Definition

integer HostNetwork( szNetworkName, szMyName, port, portv6 )

integer HostNetwork( szNetworkName, szMyName, port )

Parameters