Disconnection not fired

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

Moderators: Lapo, Bax

vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Disconnection not fired

Postby vinod11 » 02 Dec 2017, 04:49

My application is connected on wifi when I am disabling network I found that disconnection event is not fired on server side . The user remain connected on server side. I have added this in main extension . Using SF2X 2.11.1
addEventHandler(SFSEventType.USER_DISCONNECT, OnUserDisconnected.class);
User avatar
Lapo
Site Admin
Posts: 20048
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection not fired

Postby Lapo » 02 Dec 2017, 11:07

Hi,
the behavior you're seeing is normal.
Please read this article from our blog to learn more:
http://smartfoxserver.com/blog/what-rea ... tworkwifi/

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Re: Disconnection not fired

Postby vinod11 » 06 Dec 2017, 08:25

Thanks for the reply

I found the during my any function execution if server fires any events like disconnect or room join.. server stops execution of function.
why ??
User avatar
Lapo
Site Admin
Posts: 20048
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection not fired

Postby Lapo » 06 Dec 2017, 08:29

Sorry, I am not sure I understand your question.
Server side events will not interrupt your code flow. They run on a separate thread and are handled by the objects you have specified via the addEventHandler() method.

Maybe you can clarify what you mean?
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Re: Disconnection not fired

Postby vinod11 » 06 Dec 2017, 08:58

I have a class TurnRequest which extends to BaseClientRequestHandler.. have different function based on turn type.. after disconnection or room join basically when these two server events get fired TurnRequest code execution stops after few second (1-2).. for example in absense of user server timer fires turn type =1 it goes to the TurnRequest Class and stops after few second it stops in middle of any line
vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Re: Disconnection not fired

Postby vinod11 » 06 Dec 2017, 09:16

35Inside the running task. Cycle: 25
35Inside the running task. Cycle: 26
35Inside the running task. Cycle: 27
35Inside the running task. Cycle: 28
35Inside the running task. Cycle: 29
01:27:30,612 INFO [SocketReader] core.SocketReader - Socket closed: java.nio.channels.SocketChannel[closed]
35Inside the running task. Cycle: 30
01:27:31,937 INFO [Scheduler1-thread-1] sessions.DefaultSessionManager - Session removed: { Id: 5, Type: DEFAULT, Logged: Yes, IP: 202.173.127.48:50218 }
01:27:31,938 INFO [SFSWorker:Ext:3] Extensions -{GAMESFSExtension}: --------------Reached UserDisconnected(handleServerEvent)--------------
01:27:31,938 INFO [SFSWorker:Sys:3] api.SFSApi - User disconnected: { Zone: MyZone }, ( User Name: Mike, Id: 4, Priv: 0, Sess: 202.173.127.48:50218 ) , SessionLen: 74878, Type: Android
01:27:31,939 INFO [SFSWorker:Ext:3] Extensions -{GAMESFSExtension}: disconnected user:Mike
01:27:31,940 INFO [SFSWorker:Ext:3] Extensions -{GAMESFSExtension}: UNKNOWN
35Inside the running task. Cycle: 31
35Inside the running task. Cycle: 32
35Inside the running task. Cycle: 33
35Inside the running task. Cycle: 34
Trace(“Timer Fired Turntype 5”)

01:27:35,558 INFO [pool-19-thread-1577885] Extensions -{GAMESFSExtension}: TurnRequestHandler--->--------------Reached TurnRequestHandler--------------
01:27:35,562 INFO [pool-19-thread-1577885] Extensions -{GAMESFSExtension}: TurnRequestHandler--->TurnRequestHandler-->seatNumber 6
01:27:35,563 INFO [pool-19-thread-1577885] Extensions -{GAMESFSExtension}: TurnRequestHandler--->turnType----> 5
1:27:35,567 INFO [pool-19-thread-1577885] Extensions -{GAMESFSExtension}: TurnRequestHandler-------------------> turnType5
User avatar
Lapo
Site Admin
Posts: 20048
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection not fired

Postby Lapo » 06 Dec 2017, 14:28

vinod11 wrote:I have a class TurnRequest which extends to BaseClientRequestHandler.. have different function based on turn type.. after disconnection or room join basically when these two server events get fired TurnRequest code execution stops after few second (1-2)..

Do you mean that after a disconnection event if another user calls the "TurnRequest" handler it doesn't get executed?

for example in absense of user server timer fires turn type =1 it goes to the TurnRequest Class and stops after few second it stops in middle of any line

Something is not very clear.
The TurnRequest is a request handler, therefore it is expected to be invoked by the client API and it will send back a reply. That's how a request handler is supposed to work.

Here, however, it looks like you're running a Task of some sort. But I don't understand how the repeating task and the handler are connected... Can you clarify?

Thanks
Lapo

--

gotoAndPlay()

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

Re: Disconnection not fired

Postby Lapo » 06 Dec 2017, 14:32

Another strange thing I noticed in your logs is some thread names such as "pool-19-thread-1577885".
By the look of it, it seems you're running many thread pools or maybe Schedulers? With an awful lot of threads.

Can you clarify how do you use threads in your server side code?
Lapo

--

gotoAndPlay()

...addicted to flash games
vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Re: Disconnection not fired

Postby vinod11 » 06 Dec 2017, 14:39

in my game:
1. When two players join a room server send message to them and start a task using ScheduledThreadPoolExecutor that if user does not reply within 35 second play behalf of him and send Extension request to play the turn.
2. If a player (client) sends his move ScheduledThreadPoolExecutor task stops and send user move to TurnRequestHandler. In turn reuest handler according to the recived move new turnrequest is send to the client.
the above process is used for all the turns
not sure I am able to clear the scenario :(
vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Re: Disconnection not fired

Postby vinod11 » 06 Dec 2017, 14:42

in my case if client does not send his move .. server after 35 second self send extension request ( means in TurnRequstHandler the server sends a turnRequest to self)
this.extension.handleClientRequest("turnRequest ", this.sender, this.params);
vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Re: Disconnection not fired

Postby vinod11 » 06 Dec 2017, 15:01

At RoomExtension I am using :
public ScheduledThreadPoolExecutor ScheduleService = new ScheduledThreadPoolExecutor(0);
public ScheduledFuture scheduledFutureTask;

in GameManager class

Code: Select all

if(extension != null) {
            if(((SFSRoom)extension).scheduledFutureTask != null){
               if(!((SFSRoom)extension).scheduledFutureTask.isCancelled() || kerSFSRoom)extension).scheduledFutureTask.isDone()){
                  ((SFSRoom)extension).scheduledFutureTask.cancel(true);
            ((SFSRoom)extension).scheduledFutureTask = ((SFSRoom)extension).ScheduleService.scheduleAtFixedRate(new TimedServerRequest(extension, sender, extensionRequest, params,duration), 0, 1, TimeUnit.SECONDS);
               }
            }


         }

TimedServerRequest class In runnable method
if (runningCycles== duration)
                        {

                           
                           if(extension != null) {
                             if(((SFSRoom)extension).scheduledFutureTask != null){                               

                                   ((SFSRoom)extension).scheduledFutureTask.cancel(true);
                                   ((SFSRoom)extension).scheduledFutureTask = null;
                           this.extension.handleClientRequest(this.extensionRequest, this.sender, this.params);


                             }
                           }
User avatar
Lapo
Site Admin
Posts: 20048
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection not fired

Postby Lapo » 06 Dec 2017, 15:26

I am not sure what this code is supposed to do.
Is it supposed to delay the response by waiting for some time?

I feel like your problem is caused by how you're managing all these tasks. Especially because you seem to keep a reference to a task for every Room but what happens when multiple users call the same Room Extension?

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
vinod11
Posts: 11
Joined: 30 Nov 2017, 18:34

Re: Disconnection not fired

Postby vinod11 » 06 Dec 2017, 16:46

In these type of turnbased games how a Timer should be used.. Sorry I am new in java :(. I just scheduled a task and take its refrence to room class so that I can cancel it before a new turn .. I feel u are right but I can not figure out how i should do
User avatar
Lapo
Site Admin
Posts: 20048
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection not fired

Postby Lapo » 07 Dec 2017, 08:47

Just to understand, how many timers (or tasks) does a single Room need at one time?
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 3 guests