Everything’s in the title basically. I have a game where players are prompted to enter their username, and an IP adress in order to connect themselves to one of our Master Servers which in turn will put them into a match against some other player.
During the time the game connects to the Master Server and searches for a match, the player has the ability to cancel everything and go back to the main menu, in cases such as when the IP isn’t the right one. However, I noticed that you cannot call NetworkTransport.Disconnect on a ConnectionID that’s currently waiting for the Connect event response from the server, meaning you are dependant on the seemlingly hardcoded timeout way of “cancelling” a connection request. I’d like to be able to cancel it early in case the player wishes to. Are there any ways ?
I think there isn’t a way of doing it beside coding yourself a way.
Having a flag to close the connection when you recieve the connection handshake seems the way to go.
case NetworkEventType.ConnectEvent:
if (cancelFlag)
{
NetworkTransport.Disconnect(hostId, connectionId, err)
}
else {
// Your stuff
}
You can also call the NetworkTransport.Shutdown() but this is maybe not the best way to solve that problem
Yes you are right, but you can reduce the waiting time. You have two parameters for that:
ConnectionConifg.MaxConnectionAttempt - defines how many times your application will try to connect and
ConnectionConfig.ConnectionTimeout - defines timeout after that your application will thing that connect falls down. By default connecttimeout = 2000 (2s) and MaxConnectionAttempt = 10. I would not recommend to reduce first digit (as you cannot receive response faster than rtt <~ 600 ms. But you can reduce MaxConnectionAttempt, in this case you will receive signal faster.
Another obvious option, if user want to cancel connection which has not opened yet, just forget about this connection, and when you will receive connect event on that connection, just close it.