Hi,
I've been developing my game with Cocos Creator and Smartfox server. I use javascript library, since it's pure javascript then Cocos Creator can compile it to be able to run with native platform. But then it raise a problem, if user kill app from background (e.x iPhone user remove it from background stack) current session immediately terminated.
I know HRC+ is not supported in HTML5 yet, but is there any solution I can get over this issue?
HRC+ with javascript client
Re: HRC+ with javascript client
Hi,
well, there's a bigger issue if the player kills the app: even HRC+ wouldn't work.
Because the whole state of the client application has been removed from memory.
To be able to reconnect later and restart the game you need a more sophisticated and custom made "save game" functionality on the server side that allows you to store all of the client state and send it back when the user logs in again.
Does this help?
well, there's a bigger issue if the player kills the app: even HRC+ wouldn't work.
Because the whole state of the client application has been removed from memory.
To be able to reconnect later and restart the game you need a more sophisticated and custom made "save game" functionality on the server side that allows you to store all of the client state and send it back when the user logs in again.
Does this help?
Re: HRC+ with javascript client
yes, I did implement save game logic on server. I have a version of my game, developed in Objective C, once user remove app from background, connection is not terminated by Smartfox server yet, then user can login again, restore his game state.
Is this case accidentally support by HRC+?
Is this case accidentally support by HRC+?
Re: HRC+ with javascript client
Sometimes I got this error log
Exception: com.smartfoxserver.v2.exceptions.SFSRuntimeException
Message: -Unexpected- Cannot find any User for Session: { Id: 65, Type: WEBSOCKET, Logged: Yes, IP: 127.0.0.1:37560 }
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.SmartFoxServer.onSessionReconnectionTry(SmartFoxServer.java:1029)
com.smartfoxserver.v2.SmartFoxServer.access$5(SmartFoxServer.java:1024)
com.smartfoxserver.v2.SmartFoxServer$EventDelegate.run(SmartFoxServer.java:1122)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
In which case result in error "Cannot find any User for Session"?
Exception: com.smartfoxserver.v2.exceptions.SFSRuntimeException
Message: -Unexpected- Cannot find any User for Session: { Id: 65, Type: WEBSOCKET, Logged: Yes, IP: 127.0.0.1:37560 }
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.SmartFoxServer.onSessionReconnectionTry(SmartFoxServer.java:1029)
com.smartfoxserver.v2.SmartFoxServer.access$5(SmartFoxServer.java:1024)
com.smartfoxserver.v2.SmartFoxServer$EventDelegate.run(SmartFoxServer.java:1122)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
In which case result in error "Cannot find any User for Session"?
Re: HRC+ with javascript client
trungnt85 wrote:yes, I did implement save game logic on server. I have a version of my game, developed in Objective C, once user remove app from background, connection is not terminated by Smartfox server yet
To be precise, it's not terminated by the OS SmartFoxServer has nothing to do with it. It just waits for a signal from the OS.
then user can login again, restore his game state. Is this case accidentally support by HRC+?
Unfortunately no. The issue with supporting reconnection with websockets is that the HRC+ is built into the core of the server's engine. Websockets on the other hand are handled by Jetty (a different engine).
We're thinking of possible solutions, now that we have removed Netty (previous websocket engine) from the picture.
cheers
Re: HRC+ with javascript client
So with html web socket library, and I config ZoneConfigurator > User Max Idle Time with value 120, it does keep keep user connected within 120s, right?
Re: HRC+ with javascript client
trungnt85 wrote:So with html web socket library, and I config ZoneConfigurator > User Max Idle Time with value 120, it does keep keep user connected within 120s, right?
Hi, I do need to confirm this. I know html 5 not support HRC, so does Smartfox server still keep connection for logged in user within thin 120 seconds
Re: HRC+ with javascript client
I assume that with html5 web socket library, when user kills app from background, it'll send disconnect request to server
Re: HRC+ with javascript client
trungnt85 wrote:I assume that with html5 web socket library, when user kills app from background, it'll send disconnect request to server
No. This is something you can attempt to do by listening for specific events but it's not guaranteed that it will work 100% of the times.
For example if the app crashes it's likely the event will not be fired and the disconnection won't be triggered.
Re: HRC+ with javascript client
Is there any solution so I can implement HRC with html5 client. My problem is I want to let user to rejoin to last joined room when the application hang and user have to kill it from background to start again
Re: HRC+ with javascript client
Does this application hang often? If so wouldn't it be best to understand why it happens and avoid the problem entirely?
In any case, as I mentioned in a previous post, this problem goes beyond HRC because you're also loosing the client side state, when the app crashes. If Cocos allows you to save local data you could store the previous game state in a local file and reload it when the app is launched again.
As regards how to implement a reconnection system specific for your game I have no idea since you didn't explain how it works.
Is it realtime? turn based? Are game rooms private, public?
Generically speaking you could detect when a player leaves the Room and "freeze" the game for some time waiting for the player to return. Freezing doesn't necessarily means that the other players can no longer play. It may just mean that the Room cannot be joined by other people for a certain amount of time.
If the player comes back you will re-join him/her in the game, otherwise you should "unfreeze" the Room and let other people join.
Another aspect of the "frozen period" is that you will have to store all game state changes and send them back to the original client when he returns back. This is a very game-specific aspect of the system. Based on how your game works you can find way to optimize and reduce the amount of information that you need to send to the player in order to rebuild his game state on the client side.
Hope it helps
In any case, as I mentioned in a previous post, this problem goes beyond HRC because you're also loosing the client side state, when the app crashes. If Cocos allows you to save local data you could store the previous game state in a local file and reload it when the app is launched again.
As regards how to implement a reconnection system specific for your game I have no idea since you didn't explain how it works.
Is it realtime? turn based? Are game rooms private, public?
Generically speaking you could detect when a player leaves the Room and "freeze" the game for some time waiting for the player to return. Freezing doesn't necessarily means that the other players can no longer play. It may just mean that the Room cannot be joined by other people for a certain amount of time.
If the player comes back you will re-join him/her in the game, otherwise you should "unfreeze" the Room and let other people join.
Another aspect of the "frozen period" is that you will have to store all game state changes and send them back to the original client when he returns back. This is a very game-specific aspect of the system. Based on how your game works you can find way to optimize and reduce the amount of information that you need to send to the player in order to rebuild his game state on the client side.
Hope it helps
Return to “SFS2X HTML5 / JavaScript API”
Who is online
Users browsing this forum: No registered users and 34 guests