Android disconnect doesn't work

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Android disconnect doesn't work

Postby Ber4ber43 » 17 Jul 2019, 06:43

Hello World of SFS2X,

I realized that the event "addEventHandler (SFSEventType.USER_DISCONNECT, UserLogoutHandler.class);"
It does not work when used with an Android application.

How can everything work correctly with the Windows client, while the Android client doesn't work?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Android disconnect doesn't work

Postby Lapo » 17 Jul 2019, 10:41

Hi,
it does work and it should be used in Android applications as well.

With mobile devices, however, there are other issues that may prevent a disconnection to be detected when it happens (though it may be detected eventually). This depends on the protocols that are currently used in our networks, mainly TCP.

We've written two detailed articles on this subject that can be found here:
https://smartfoxserver.com/blog/handlin ... e-devices/
https://smartfoxserver.com/blog/what-re ... tworkwifi/

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Re: Android disconnect doesn't work

Postby Ber4ber43 » 17 Jul 2019, 16:18

Hi Lapo,
many thanks for your answer, but unfortunately it doesn't help me.
My code client for Disconnection:

Code: Select all

     public static void Disconnect ()
     {
         Debug.Log("Trigger?");   //No -.-
         if (sfsConnection! = null && sfsConnection.IsConnected)
         {
             sfsConnection.Disconnect ();
         }
     }


But nothing happens nothing.

While the same method if I call it in a Windows client, it closes the connection.

I use Socket connection, by sfsConnection.ConnectionMode
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Android disconnect doesn't work

Postby Lapo » 18 Jul 2019, 08:38

Hi,
can you please explain more clearly what is the problem, because I can't follow.

In the opening post you said that the server-side disconnection handler does not work, but you didn't specify under which circumstances.
Now it looks like you're saying that it doesn't work 100% of the times, even when calling the disconnect method from client side.
Is this the case?

Also plase specify:
1) Server version you're using
2) Slient API version you're using
3) Unity version
4) Is this a local network test or online test?
5) Android version used in the test
6) Is the test running in an emulator or actual device, if device which brand/model?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Re: Android disconnect doesn't work

Postby Ber4ber43 » 18 Jul 2019, 10:50

Yes, when the Disconnet method is called by the client, if the client is a Windows application everything works correctly. While if the client is an Android application the Disconnect method is not called.

- SmartFoxServer 2X (2.13.5) and BlueBox-2X Service (3.3.0)
- Unity Version 2018.3.12f1 Personal
- Windows: Local Test - Android: Online Test (I have a DNS, all my project work, only the Disconnect doesn't work)
- Android Version 8.0.0
- My Samsung S7 Edge phone
Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Re: Android disconnect doesn't work

Postby Ber4ber43 » 18 Jul 2019, 11:03

I testing on BlueStacks and the Disconnection doesn't work
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Android disconnect doesn't work

Postby Lapo » 18 Jul 2019, 14:34

What is version of the client Unity API you're using?
You can print out in the Unity console the Version property of your SmartFox instance, if you don't know or don't remember.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Android disconnect doesn't work

Postby Lapo » 18 Jul 2019, 15:01

Also I would like to understand a bit better.
When you connect and login with a client you will see two messages in the server side logs that look like this:

Code: Select all

17:05:15,148 INFO  [qtp1379031360-48] sessions.DefaultSessionManager     - Session created: { Id: 4, Type: WEBSOCKET, Logged: No, IP: 127.0.0.1 } on Server port: 8080 <---> 49163
17:05:15,396 INFO  [SFSWorker:Sys:1] api.SFSApi     - User login: { Zone: BasicExamples }, ( User Name: Guest#0, Id: 0, Priv: 0, Sess: 127.0.0.1:49163 ) , Type: Unity / .Net

The first signals that a connection was created, the second that a User was created, after the successful login.

When you call the SmartFox.Disconnect() method you should two other log messages:

Code: Select all

17:05:16,488 INFO  [qtp1379031360-48] sessions.DefaultSessionManager     - Session removed: { Id: 4, Type: WEBSOCKET, Logged: Yes, IP: 127.0.0.1:49163 }
17:05:16,492 INFO  [SFSWorker:Sys:2] api.SFSApi     - User disconnected: { Zone: BasicExamples }, ( User Name: Guest#0, Id: 0, Priv: 0, Sess: 127.0.0.1:49163 ) , SessionLen: 1098, Type: Unity / .Net

Which tell you that the connection was closed and the User removed.

Does the server output these two messages when you disconnect?
If not, you should run a second test where you disconnect by shutting down the App rather than calling the Disconnect method.

Let us know
Lapo

--

gotoAndPlay()

...addicted to flash games
Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Re: Android disconnect doesn't work

Postby Ber4ber43 » 18 Jul 2019, 16:42

Version Api Unity: 1.7.9
Sorry, i have this Version Api Unity: API v1.7.8.1

When I log in I get these lines in the SmartFoxServer2x console:

Code: Select all

17:43:32,131 INFO  [main] v3.SessionFilter     - BlueBox-2X Service (3.3.0) READY.
17:43:48,806 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 127.0.0.1:64283 } on Server port: 9933 <---> 64283
17:43:48,813 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 127.0.0.1:64284 } on Server port: 9933 <---> 64284
17:43:48,820 INFO  [SocketReader] sessions.DefaultSessionManager     - Session removed: { Id: 1, Type: DEFAULT, Logged: No, IP: 127.0.0.1:64283 }
17:43:48,894 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: Login }, ( User Name: 25, Id: 0, Priv: 0, Sess: 127.0.0.1:64284 ) , Type: Unity
17:43:48,894 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: Login }, ( User Name: 25, Id: 0, Priv: 0, Sess: 127.0.0.1:64284 ) , Type: Unity


When I log out from a Windows client it never gave me any errors, but today it gave me this warning:

Code: Select all

18:16:43,117 INFO  [SFSWorker:Ext:4] managers.SFSRoomManager     - Room removed: { Zone: Login }, [ Room: 96, Id: 13, Group: clan, isGame: false ], Duration: 10379
ID USER 22
User logout successful:22
18:34:33,451 WARN  [qtp315805187-83] http.HttpParser     - Illegal character 0x16 in state=START for buffer HeapByteBuffer@18047676[p=1,l=215,c=8192,r=214]={\x16<<<\x03\x01\x00\xD2\x01\x00\x00\xCe\x03\x03\xFe\xEe\xEb1\xB3\x14\xFe...\x03\x02\x03\x03\x02\x01\x02\x02\x02\x03\x00\x0f\x00\x01\x01>>>w-form-urlencoded...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
18:34:33,451 WARN  [qtp315805187-83] http.HttpParser     - bad HTTP parsed: 400 Illegal character 0x16 for HttpChannelOverHttp@3dd88525{r=0,c=false,a=IDLE,uri=null}


When an Android client logs out, nothing appears on the server, as if the disconnection had never arrived. I tried to log out without closing the app, the server doesn't receive anything anyway.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Android disconnect doesn't work

Postby Lapo » 19 Jul 2019, 06:49

Logging out and disconnecting are two different things.
If you call SmartFox.Logout() from client side you will simply leave the current Zone, without closing the connection to the server, so that you can log into another Zone.

On the other hand if you call SmartFox.Disconnect() you will shut down the current connection, terminating the session with the server (and thus leaving the Zone etc...)

Maybe it's you're just using "logout" to mean disconnect, but I want to make this is clear so that we understand what we're talking about.

When an Android client logs out, nothing appears on the server, as if the disconnection had never arrived. I tried to log out without closing the app, the server doesn't receive anything anyway.

Without closing the app?
It would be helpful if you tried in two different ways:
1) by invoking SmartFox.Disconnect()
2) by closing the client app

and tell us what the effects are, in the server side logs.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Re: Android disconnect doesn't work

Postby Ber4ber43 » 19 Jul 2019, 09:32

I'm using SmartFox.Disconnect ()

Tests made with Windows application:
- Local to server: The server receives from Disconnection
- Through the Internet: The server does NOT receive the Disconnection

Tests made with Android application:
- Local to server: The server does NOT receive the Logout
- Through the Internet: The server does NOT receive the Disconnection

After a few seconds, the servers saw Disconnection

Code: Select all

11:32:10,620 INFO  [pool-1-thread-1] sessions.DefaultSessionManager     - Session removed: { Id: 1, Type: BLUEBOX, Logged: Yes, IP: 31.27.225.188 }
11:32:10,621 INFO  [SFSWorker:Sys:1] sessions.DefaultSessionManager     - Session removed: { Id: 1, Type: BLUEBOX, Logged: Yes, IP: 31.27.225.188 }
11:32:10,630 INFO  [SFSWorker:Sys:1] api.SFSApi     - User disconnected: { Zone: Login }, ( User Name: 23, Id: 0, Priv: 0, Sess: 31.27.225.188 ) , SessionLen: 72712, Type: Unity
11:32:10,727 INFO  [SFSWorker:Ext:2] managers.SFSRoomManager     - Room removed: { Zone: Login }, [ Room: 96, Id: 3, Group: clan, isGame: false ], Duration: 72791
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Android disconnect doesn't work

Postby Lapo » 19 Jul 2019, 14:30

Hi,
we've tested these scenarios with a basic Unity connector, based on the same API (1.7.8 ) both locally and with a remote server, using an Android build. No problems were found.

Tests made with Windows application:
- Local to server: The server receives from Disconnection
- Through the Internet: The server does NOT receive the Disconnection

This is interesting. If testing from Windows to a remote server causes issues it sounds like there's a network problem. Where is the server hosted? Have you tried testing with another client from another network?

When you say that the server does not receive the disconnection do you mean:
1) It doesn't log the standard "User disconnected" message?
2) It doesn't trigger the server side event?
3) Both?

If you want you can send us the IP address of your remote test server and we can try a couple of remote tests. You can use a private message.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Re: Android disconnect doesn't work

Postby Ber4ber43 » 19 Jul 2019, 23:17

The server is hosted on my PC, I use the https://www.noip.com service for DNS.

All local tests are done by my PC.
All internet tests are done by another network.

When you say that the server does not receive the disconnection do you mean:
1) It doesn't log the standard "User disconnected" message?
2) It doesn't trigger the server side event?
3) Both?

Both

Privately I can give you my DNS, but we have to agree on when to have to do the test.
I have just done the same tests with the Firewall disabled, all the results are the same as the previous ones.
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Android disconnect doesn't work

Postby Lapo » 20 Jul 2019, 07:20

It sounds like it's a network issue and the fact that the server is self-hosted makes it more probable.
What firewall are you using?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Ber4ber43
Posts: 79
Joined: 30 Apr 2019, 14:35

Re: Android disconnect doesn't work

Postby Ber4ber43 » 20 Jul 2019, 07:35

The Firewall that has Windows 10, but I disabled it and does not change anything.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 151 guests