Disconnection/Reconnection in Javascript API

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

gopalrgpl
Posts: 11
Joined: 27 Mar 2018, 05:00

Disconnection/Reconnection in Javascript API

Postby gopalrgpl » 05 Jun 2018, 09:22

How to handle disconnection and reconnection in SFS2X Javscrit API,

For example in socket.io the library attempts to connect for a specific number of times, if connected within the specific time, connection is established.
Do we have one, like that in SmartFox????

Or should we write our own logic for re-connection from Client Side Javascript.


And when we are trying to connect to SFS server when there is no internet , will there be any specific event triggered from sfs client library stating that there is no connection or we have to handle it manually in client side???
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection/Reconnection in Javascript API

Postby Lapo » 05 Jun 2018, 13:29

Hi,
for socket based connections we support automatic transparent reconnection.
For JS however we don't, as the Websocket engine we use is third party (Eclipse's Jetty) and we don't have full control of the low level details to implement a similar mechanism.

You can build your own client-side reconnection system by retrying a certain amount of times, as you suggested.
Just keep in mind that every time a connection fails you will need to create a new SmartFox object.

And when we are trying to connect to SFS server when there is no internet , will there be any specific event triggered from sfs client library stating that there is no connection or we have to handle it manually in client side???

There is an SFSEven.CONNECTION event with a success parameter which is set to false if the connection failed.

However there is no specific parameter telling you what caused the failure as there could be all kinds of reasons for that. If you want to check that the client is online (i.e. it has an active network) you can do it directly in your application and maybe provide feedback to the user if internet is down.
Here's an article showing how it's done:
https://davidwalsh.name/detecting-online

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
gopalrgpl
Posts: 11
Joined: 27 Mar 2018, 05:00

Re: Disconnection/Reconnection in Javascript API

Postby gopalrgpl » 06 Jun 2018, 08:32

Thanks for the support.

Can we expect the retry logic for attempting re-connection in websockets through sfs api , in the library itself in future updates,
passing the reconnection attempts to the config when creating the smartfox instance, so that it would be really great for developers ,that the library would try reconnecting for athe given number of times and emit en event on failure to connect within the specified attempts
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Disconnection/Reconnection in Javascript API

Postby Lapo » 06 Jun 2018, 13:40

If Jetty allows it, yes. I am not sure it does though, but we'll investigate.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
gopalrgpl
Posts: 11
Joined: 27 Mar 2018, 05:00

Re: Disconnection/Reconnection in Javascript API

Postby gopalrgpl » 06 Jun 2018, 16:18

Thank you, we are expecting a new release soon

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 17 guests