// host a network called ExampleNetwork and give this machine the client name Host
networkId = HostNetwork("ExampleNetwork", "Host", 1025)
do
// check that the network is set up ok (if the host returns 0 for isnetworkactive at any point, the network has failed)
if networkId > 0 and IsNetworkActive(networkId)
// print details of the network, including client number (this number will include the host)
Print("Network Active")
Print("Number of Clients: " + Str(GetNetworkNumClients(networkId)))
// cycle through all the clients
clientId = GetNetworkFirstClient(networkId)
while clientId > 0
// print the client details
Print("Client " + Str(clientId))
// if the client has disconnected, it needs to be cleaned up and removed
if GetNetworkClientDisconnected(networkId, clientId)
// if the first item of client user data is not set (0 is default)
if GetNetworkClientUserData(networkId, clientId, 0) = 0
// set the first item of client user data to 1 so that we know we have already cleaned up (clients persist for a few cycles after being deleted)
SetNetworkClientUserData(networkId, clientId, 0, 1)
// delete the client (this will not be instant)
DeleteNetworkClient(networkId, clientId)
endif
Print(" Client Disconnected")
else
// if the client is connected, print its unique identifying name (chosen in the joinnetwork or hostnetwork commands)
Print(" Client Connected")
Print(" Name: " + GetNetworkClientName(networkId, clientId))
endif
// as this machine is the host, we can work out if the current client is the host by checking it against the current machine's id
if clientId = GetNetworkMyClientId(networkId)
Print(" Client Is Host")
else
Print(" Client Is Client")
endif
// move on to the next client
clientId = GetNetworkNextClient(networkId)
endwhile
else
Print("Network Setup Failed")
endif
// update the screen
Sync()
loop
Help make AGK better by submitting an example for this command! (All examples are subject to approval)