Detecting when server is unreachable

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

User avatar
Zelek
Posts: 36
Joined: 24 Jun 2010, 22:36

Detecting when server is unreachable

Postby Zelek » 28 Feb 2013, 04:24

Very basic question here, I fear I'm probably missing something obvious. How can the client detect when the server is unreachable (perhaps it's down or hasn't been started)? SmartFox.Connect() gets called, but the OnConnection event listener is never triggered. Is there some other event I can listen for, or some property that denotes that a connection was attempted and couldn't be made?
User avatar
Zelek
Posts: 36
Joined: 24 Jun 2010, 22:36

Re: Detecting when server is unreachable

Postby Zelek » 28 Feb 2013, 05:08

Well, well...maybe I'm not crazy after all! I just went through the connector example line by line, which successfully calls "OnConnection" even when the server is unavailable. The only difference in my project is that I'm using a more recent version of the Unity plugin (2-9-2013). Sure enough, when I reverted to the older version of the plugin from the connector example (4-9-2012), it works. Perhaps a bug was introduced in the most recent update to the Unity plugin?
User avatar
Lapo
Site Admin
Posts: 21091
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Detecting when server is unreachable

Postby Lapo » 28 Feb 2013, 09:35

I am not sure if it was introduced in the last version, because it doesn't seem to work with previous versions as well.
We'll take a closer look before releasing the next update.

Meanwhile a simple workaround is to detect the failure in loading the socket policy. Since this operation is required before starting the connection you can use something like this to detect if the server is online:

Code: Select all

if (Application.isWebPlayer || Application.isEditor)
{
   if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500))
   {
      // Handle the problem here...
   }
}
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 21091
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Detecting when server is unreachable

Postby Lapo » 06 Mar 2013, 17:27

UPDATE:
We have a preview release of the Unity API that fixes several issues as discussed in this forums.
Please make sure to download the DLL and try it in your project.

Please let us know if it fixes your problems.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 3 guests