Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Unexpected Behaviour with HostNetwork

Author
Message
ChrisTheProgrammer
7
Years of Service
User Offline
Joined: 10th Dec 2016
Location:
Posted: 8th Jan 2017 06:34
Hi Everyone,

I have a network game and HostNetwork and JoinNetwork work as documented. The following is not the behaviour that I would have expected, and I am looking for someone who can explain why the following is occurs.

On computer 1, I run this code...

NetworkID = HostNetwork("MyAwesomeGame", "HostPlayer", 1025)
if NetworkID > 0
if IsNetworkActive(NetworkID) = 1
print("Life is good")
....loop to wait for clients
endif
endif

Code above works well, and client running JoinNetwork on computer 2 works perfectly.

But now if on computer 2, I run the same code to create a second host. I expect the NetworkID to be zero or the IsNetworkActive to fail, because I have two hosts with the same networkname, hostname, and port. I was then going to increase my port until I found an available port to host on. I am creating a simple two player game, and if a third player creates a hosted game I just want to bump him up to the next available port.

Instead, both computers are happily getting through my if statements and I seem to have two hosts with the same networkname, hostname, and port.

Tomorrow I will find a third computer to see which one a client will connect to... but I was hoping that someone who has experienced this can advise.

Thank you,

Chris
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 8th Jan 2017 16:54
The third client would connect randomly to either host, depending on which one it noticed first. The client can connect to a host on port 1025 as well as host its own network on port 1025. This is because a client connecting to a host uses an outgoing port number, which is assigned randomly by the operating system, so it's port 1025 is still free to host a network of its own.
ChrisTheProgrammer
7
Years of Service
User Offline
Joined: 10th Dec 2016
Location:
Posted: 8th Jan 2017 18:16
Hi Paul,

If I understand your answer, multiple AppGameKit Networks can live on the same port within a network.

If I execute SetNetworkNoMoreClients when Host 1 starts handshaking with Client 1... Host 2 will be the only one waiting for Client 2.

If my assumption is correct, thank you. If not, can you elaborate further?

Best regards,

Chris
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 8th Jan 2017 19:29
Quote: "multiple AppGameKit Networks can live on the same port within a network"

Yes, as long as they are all hosted by a different machine. A single machine can only host one network on a specific port

Quote: "If I execute SetNetworkNoMoreClients when Host 1 starts handshaking with Client 1... Host 2 will be the only one waiting for Client 2. "

Correct, after SetNetworkNoMoreClients Client 2 would no longer be able to see the network on Host 1, and would not be able to connect to it even if it tried.

Login to post a reply

Server time is: 2024-09-29 21:15:03
Your offset time is: 2024-09-29 21:15:03