# 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.
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 )

UINT agk::JoinNetwork( const char *szIP, UINT port, const char *szMyName )

integer JoinNetwork( szNetworkName, szMyName )

UINT agk::JoinNetwork( const char *szNetworkName, const char *szMyName )

## Parameters

- szIP - The IP address of the host to connect to, can be IPv4 or IPv6
- port - The port to connect to.
- szMyName - The name to use in identifying this client.
- szNetworkName - The name of the network to connect to.