Following this example with C++ equivalents:
https://www.appgamekit.com/documentation/guides/8_networking.htm
The function agk::GetNetworkNumClients(iNetID) returns a 1 when the network is created (which is correct as the server also counts as 1 connection) However whenever a client of a 2nd application instance connects, the server does not update, still showing that theres only one connection. However the client reports 2 connections with the same function after connection.
for (int x = 1; x <= agk::GetNetworkNumClients(iNetID); x++) {
if (x == 1) {
id = agk::GetNetworkFirstClient(iNetID);
agk::Print(id);
}
else {
id = agk::GetNetworkNextClient(iNetID);
agk::Print(id);
}
}
So the above loop is straight from the examples in the AppGameKit docs. It is supposed to go through every connected client on the AppGameKit server hosted network (in the example it was checking for disconnected clients and deleting them from the connection but I'm also using this for adding player data to an array).
Now here's the weird part. IF in the server, I'm going to place the above code within this if statement:
if (agk::GetNetworkNumClients(iNetID) > 1) {
for (int x = 1; x <= agk::GetNetworkNumClients(iNetID); x++) {
if (x == 1) {
id = agk::GetNetworkFirstClient(iNetID);
agk::Print(id);
}
else {
id = agk::GetNetworkNextClient(iNetID);
agk::Print(id);
}
}
}
Then the server WILL report 2 connections. So for some reason if I start cycling through the clients on the network ONLY after there's more than 1 connection it works. I'm not even doing anything with these connections. I'm just reading their ID. that's all.
The logic of the loop above should make sense. If the server is the only one online then it would still return a 1 connection. 1 (xx=1) is equal to 1 (return of the function) so it should still get the ID from GetNetworkFirstClient(iNetID);.
But it's not even that I'm not getting the id from GetNetworkFirstClient(iNetID);. It's that the server still reports only 1 connection.
I can also do this instead (leave the loop but comment out all the ID retrieval stuff):
for (int x = 1; x <= agk::GetNetworkNumClients(iNetID); x++) {
//if (x == 1) {
// id = agk::GetNetworkFirstClient(iNetID);
// agk::Print(id);
//}
//else {
// id = agk::GetNetworkNextClient(iNetID);
// agk::Print(id);
//}
}
This will effectively ALSO report 2 connections. So something about the agk::GetNetworkNextClient(iNetID); is screwing up the engine.
Eisenstadt Studio: Eisenstadtstudio.com
Composers Page: Milesthatch.net