How to make Unity wait until Server is ready before attempting to connect?

FadiB
FadiB
edited April 2020 in Photon Server
This is a very simple question really, how do I make Unity wait until the Self-hosted server is up and running before attempting to connect to it? Currently I have made Unity wait 5 seconds before doing:
PhotonNetwork.ConncetUsingSettings();

However, I can never be sure how long it will take for the User Machine to start the server before attempting to connect to it. I want this to be automated following this simple sequence:

  1. User starts application.
  2. User Selects that they will be Server. (Between Server or Client)
  3. User Enters IP
  4. User Press on Connect button
  5. Server will now launch in the background
  6. Game will automatically connect once the Server is up and ready.


The problem I have right now is that if the server takes too long to launch, Photon throws an error stating that it could not connect to the server. Pressing the connect button again after this will connect the user to the server if it is up and running. But I do not want this to be the case. But instead follow the sequence stated above.

Is there a way to do this without having to add a delay and follow the sequence stated above?

Best Answer

Answers

  • Intercepting the exception yielded no good result. However, I did try to start a connection loop with a 0.5s delay and it worked. Thanks for a quick answer.