Forum General No Disconnect event received

Any issues or discussions relating to Unity development are welcome here.

No Disconnect event received

Postby impersogame » July 15th, 2015, 1:36 pm

We have some difficulties in handling disconnect (Unity on PC and MAC).
When we do the tests (imitate the connection failure) the disconnect event doesn't fire.

Here is the test code:

Code: Select all
public void joinToRoom(string name, string roomType, Dictionary<string,string> dct)
{
  MainClient.Multiplayer.CreateJoinRoom (name, roomType, true, dct, null,
                                         delegate(Connection value) {
   string n = name;
   string r = roomType;
   var info = new mdl_RoomInfo(value,roomType);
   if (!roomConnections.ContainsKey(name))
   {
    roomConnections.Add(name,info);

    if (roomOnConnect.ContainsKey(roomType))
     roomOnConnect[roomType](n,info);

    value.OnDisconnect += delegate(object sender, string message) {
     Debug.Log("Room disconnect " + sender.ToString() + "  " + message); // <-- Debug.Log() is never displayed
     if (roomOnDisconnect.ContainsKey(roomType))
     {
      roomOnDisconnect[roomType](n,info);
      roomConnections.Remove(name);
     }
    };
    value.OnMessage += delegate(object sender, Message e) {
     if (roomOnMessage.ContainsKey(roomType))
      roomOnMessage[roomType](n,info,e);
     };
   } else {
    value.Disconnect();
   }
                                        }, OnError);
}

Need help.
impersogame
Paid Member
 
Posts: 33
Joined: May 17th, 2013, 4:36 pm

Re: No Disconnect event received

Postby Guillaume » July 16th, 2015, 10:59 am

Have you debugged step by step that your code is going in the first "if" statement and that your disconnect event are registered ?
How do you manage to simulate the disconnection ? By code on the server ? Have you tried to just shut off your development server instead to simulate the disconnection ?
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: No Disconnect event received

Postby impersogame » July 16th, 2015, 12:54 pm

Yes, we checked that we got into the first "if".
We simulate the disconnection the hard way. We're working with a YGN sever (no development server) + Unity editor then we shut off the machine's WiFi. Then we got nothing.
impersogame
Paid Member
 
Posts: 33
Joined: May 17th, 2013, 4:36 pm

Re: No Disconnect event received

Postby Guillaume » July 16th, 2015, 1:17 pm

I'm not sure it can simulate the behavior correctly.
If you shut off the Wifi, then you network interface is actually totally losing all his routing information (IP Address, Netmask, Gateway etc.).

It's not related to a pinging issue then, so how can you be sure that you have the correct expected behavior.
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: No Disconnect event received

Postby impersogame » July 17th, 2015, 8:15 am

OK. We did more careful tests.
This time we turn off the router, so wifi stays active. Still nothing...
The only guess is that it's editor bug not the build. We will test the build.
Test code:

Code: Select all
public void OnRoomConnectionSuccess (string name, mdl_RoomInfo info)
{
  Debug.Log ("Base Room Connection success");
  BaseRoom = info.connection;
  IsConnected = true;

  PlayerSettingsController.LoadPlayerSettings ();
  ShopController.loadPlayerBalance ();
  ShopController.loadPlayerBalanceKey ();

  Debug.Log("Playce debug disconnect listener");
  BaseRoom.OnDisconnect += HandleOnDisconnect;
}

void HandleOnDisconnect (object sender, string message)
{
  Debug.LogError("Disconnect from base room");
}


UPDATE: we tested the Mac build with the same result.
The strange thing is that when we turn off the router, every program (Skype, etc.) reacts accordingly. But not the YGN client... It keeps sending requests to server.
To dig it further it would be helpful to know how to determine on client that the connection with server is lost.
impersogame
Paid Member
 
Posts: 33
Joined: May 17th, 2013, 4:36 pm

Re: No Disconnect event received

Postby Guillaume » July 17th, 2015, 10:41 am

On my project two things can happen:

Case 1, i'm on the PlayerIOError case, nothing weird to do.
Case 2, operation is taking longuer than expected. I'm actually using a CoRoutine in my code, that simulate a Timeout i have configured. If it Timeout according to my value, i directly call my Failure delegate event automatically.
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: No Disconnect event received

Postby impersogame » July 17th, 2015, 11:28 am

Is there any way to determine that connection to server (room) is lost using the Player.IO API? Or we are in need to write our own code to monitor the connection state?
impersogame
Paid Member
 
Posts: 33
Joined: May 17th, 2013, 4:36 pm

Re: No Disconnect event received

Postby Guillaume » July 17th, 2015, 11:37 am

I don't know. Normally it must work as expected. I don't rely on server Disconnection because i'm actually using the Multiplayer service as a HTTP Service like, i mean like using Methods, waiting for result, then closing the connection myself on the client side.

It would be nice if you can have a response from YGN Team.
Also a new version of the SDK is available since the 15 July. Have you tested it ?
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: No Disconnect event received

Postby impersogame » July 19th, 2015, 10:56 am

Yes, we tested new version with same result.
Our current guess is that the disconnect mechanism was initially designed for web applications (so it's expecting some leverage from http events).
Anyway I'm still trying to reach YGN team. Maybe we'll get their response.

UPDATE: Server logic correctly gets disconnects from players. Seems like it's absent in Unity client only.
impersogame
Paid Member
 
Posts: 33
Joined: May 17th, 2013, 4:36 pm

Re: No Disconnect event received

Postby Guillaume » July 20th, 2015, 7:56 pm

Scam
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France

Re: No Disconnect event received

Postby Henrik » July 22nd, 2015, 5:49 pm

That seems more like a problem with Unity's socket implementation. If the underlying socket is closed by the OS, but Unity doesn't propagate that upwards into game code and instead pretending the socket is still open, there's not a lot we can do about that.
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: No Disconnect event received

Postby impersogame » July 23rd, 2015, 11:31 am

Thanks for the answer!
We have some experience with other C# frameworks like Photon and their disconnect solutions works fine with Unity.
1) How can we check that this problem is on Unity side?
2) What steps can we take to debug it more thoroughly?
3) If we couldn't manage to use YGN disconnect API, what approach you can advise to detect disconnect on client?
impersogame
Paid Member
 
Posts: 33
Joined: May 17th, 2013, 4:36 pm

Re: No Disconnect event received

Postby Guillaume » July 23rd, 2015, 2:47 pm

Hi impersogame,

Have you tried to see if the behavior is the same in Unity if you use the Plugin Good Ol'Socket on the Unity Asset Store ?
If i'm not wrong, Photon rely on this library in order to use Socket on Unity 4.x Free versions...But i'm not sure either.
Guillaume
 
Posts: 277
Joined: March 28th, 2014, 1:59 am
Location: France


Return to General