JoinNetwork

Description

Joins an AGK network hosted by another app. The network is specified by name, or by IP address and port number. For named networks the app will look for any AGK networks broadcast with that name and connect to it if found. Alternatively using an IP address and port number will attempt a direct connection to the host. In the case of internet connections an IP and port is the only way to connect as broadcasts will not leave the local area network. IP addresses can be IPv4 or IPv6 depending on what IP addresses the host is using (it could have one or more of each).

You may detect all the networks available for connecting to by setting up a broadcast listener and listening for the broadcasts yourself, you could then display a list of discovered networks to the user to let them decide which one to connect to.

Warning, if the device listening for broadcasts is an iOS device then it may not be able to receive broadcast packets without permission from Apple. As of writing receiving is still allowed but sending requires permission from Apple, this may change in future.

This function does not connect immediately, it returns a network ID and continues to attempt to connect in the background. You can detect when a connection is made by checking the GetNetworkNumClients is greater than 1, indicating that at least the local client and server client have been detected. If IsNetworkActive returns 0 at any time then the connection to the server failed and the network should be closed, you may attempt to reconnect by opening a new network.

Once connected the app becomes a client of the network, along with the host and any other clients that have connected to it. 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.

You must identify your client with a client name that will be visible to other clients, the client name does not need to be unique.

Returns a network ID to use when interacting with this network.

Does not work when exported to HTML5

Definition

integer JoinNetwork( szIP, port, szMyName )

integer JoinNetwork( szNetworkName, szMyName )

Parameters