SFSEventType.USER_DISCONNECT

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

Moderators: Lapo, Bax

unity.webmyne
Posts: 24
Joined: 13 Feb 2017, 09:49

SFSEventType.USER_DISCONNECT

Postby unity.webmyne » 05 Jun 2017, 13:42

Hello Support Team,

We are facing issue regarding not getting SFSEventType.USER_DISCONNECT in java code. when user login into smartfox zone in android device and due to power-off occurs when battery is too low. Following is our code description.

In LoginMain Extension we have initialize java class for handling USER_DISCONNECT event.

addEventHandler(SFSEventType.USER_DISCONNECT, LogoutZoneHandlerExt.class);

In below class

Code: Select all

package com.game;

import java.sql.Connection;
import java.sql.SQLException;

import com.smartfoxserver.v2.SmartFoxServer;
import com.smartfoxserver.v2.core.ISFSEvent;
import com.smartfoxserver.v2.core.SFSEventParam;
import com.smartfoxserver.v2.core.SFSEventType;
import com.smartfoxserver.v2.db.IDBManager;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.exceptions.SFSException;
import com.smartfoxserver.v2.extensions.BaseServerEventHandler;

public class LogoutZoneHandlerExt extends BaseServerEventHandler {


   Connection cn = null;
   
   public void handleServerEvent(ISFSEvent event) throws SFSException
   {
      
      if(event.getType() == SFSEventType.USER_LOGOUT)
      {
          trace(user.getName()+"USER_LOGOUT called from loginextension");
      }
      else if(event.getType() == SFSEventType.USER_DISCONNECT)
      {
          trace(user.getName()+"USER_DISCONNECT called from login extension");
          SmartFoxServer.getInstance().getAPIManager().getSFSApi().logout(user);
      }
      
      
   }
}




We are not able to logout user who disconnect and not getting any trace log. this will not happen all time. sometime this code will logout user and giving log of trace and sometimes not. We want to know actually in which scenario there is possibilities that in java code we can not able to get event of SFSEventType.USER_DISCONNECT
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSEventType.USER_DISCONNECT

Postby Lapo » 05 Jun 2017, 15:15

Yes,
this is normal. A disconnection requires exchanging 4 messages between client and server. In certain situations, such as shutting down the wifi or pulling an ethernet cable this communication is not possible and no disconnection event is fired.

This is not the server's fault. The disconnection doesn't trigger at any level in the TCP stack, so there's nothing you can do about it besides waiting that the normal TCP timeout triggers and gets rid of it.

Code: Select all

      else if(event.getType() == SFSEventType.USER_DISCONNECT)
      {
          trace(user.getName()+"USER_DISCONNECT called from login extension");
          SmartFoxServer.getInstance().getAPIManager().getSFSApi().logout(user);
      }


Sorry but this is useless. The DISCONNECT event is triggered after the client has already been disconnected, so calling logout() on a disconnected user is redundant. The event's purpose is just to allow your code to react to such an event in order to clear your game state.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
unity.webmyne
Posts: 24
Joined: 13 Feb 2017, 09:49

Re: SFSEventType.USER_DISCONNECT

Postby unity.webmyne » 06 Jun 2017, 07:13

Hello Lapo,
Thank for you quick reply.If i am not wrong than you saying that when disconnect event fire user already logout.so no need to make user explicitly logout from zone if user disconnect.
In our game ideal timeout is required more as our player can be spectator around 3 minutes. so what we can do for this issue? how we can eliminate this issue.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSEventType.USER_DISCONNECT

Postby Lapo » 06 Jun 2017, 07:21

unity.webmyne wrote:Hello Lapo,
Thank for you quick reply.If i am not wrong than you saying that when disconnect event fire user already logout.so no need to make user explicitly logout from zone if user disconnect.

Yes, correct.

In our game ideal timeout is required more as our player can be spectator around 3 minutes. so what we can do for this issue? how we can eliminate this issue.

Sorry, I don't understand.
You need a timeout for spectators? Can you clarify what you're trying to do?
Lapo

--

gotoAndPlay()

...addicted to flash games
unity.webmyne
Posts: 24
Joined: 13 Feb 2017, 09:49

Re: SFSEventType.USER_DISCONNECT

Postby unity.webmyne » 06 Jun 2017, 11:08

Hello Lapo,
As per your first reply, (SFSEventType.USER_DISCONNECT)The event's purpose is just to allow your code to react to such an event in order to clear your game state. We are doing same in USER_DISCONNECT but event is not fired sometime so we can not able to clean our database record.
IN your first reply you also said that, The disconnection doesn't trigger at any level in the TCP stack, so there's nothing you can do about it besides waiting that the normal TCP timeout triggers and gets rid of it.
but we have configured timout of 30000 seconds in smartfox dashboard as our player can idle upto 30000 second.so we can not depend on
TCP timeout triggers and clean our game state in this scenario when we can not get SFSEventType.USER_DISCONNECT. Please you can provide any alternate option for this.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSEventType.USER_DISCONNECT

Postby Lapo » 06 Jun 2017, 13:30

unity.webmyne wrote:Hello Lapo,
As per your first reply, (SFSEventType.USER_DISCONNECT)The event's purpose is just to allow your code to react to such an event in order to clear your game state. We are doing same in USER_DISCONNECT but event is not fired sometime so we can not able to clean our database record.
IN your first reply you also said that, The disconnection doesn't trigger at any level in the TCP stack, so there's nothing you can do about it besides waiting that the normal TCP timeout triggers and gets rid of it.
but we have configured timout of 30000 seconds in smartfox dashboard as our player can idle upto 30000 second.so we can not depend on
TCP timeout triggers and clean our game state in this scenario when we can not get SFSEventType.USER_DISCONNECT. Please you can provide any alternate option for this.

The timeout I am talking about is the operating system's own TCP timeout.

As I mentioned opening/closing a connection requires message exchange. If that's not possible a disconnection will not occur, and both sides of the communication will keep "thinking" that the connection is active.

To avoid connections getting stuck forever the OS has its own timeout which triggers after a certain amount of time (it's different for every OS) after the last message has been sent or received.

Hope it's clear.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 64 guests