Page 1 of 1

HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 08:20
by carbon_crystal
Hi. as title said, I'm using JS Client to connect to Smartfoxserver 2X, but it can't success.
I have tried to connect to server by pure Websocket API then successful, with SFS2X client, I get only the info below by all time and nothing else

Code: Select all

[ SFS2X | INFO ] Attempting connection to server
[ SFS2X | INFO ] Sending request 'HandshakeRequest' to server


This is my code and info

Code: Select all

      app.sfs = new SFS2X.SmartFox();
      app.sfs.debug = true;
      app.sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
      app.sfs.addEventListener(SFS2X.SFSEvent.EXTENSION_RESPONSE, onExtensionResponse, this);
      app.sfs.connect("localhost", 8080, false);
      
      function onConnection(event) {
         if (event.success) {
            console.log("Connected to SmartFoxServer 2X!");
         } else {
            alert("Failed!");
         }
      }
      
      function onExtensionResponse(event) {
         console.log(event);
      }


Server version: Smartfoxserver 2X v2.13
All server configurations is default.
Client API:
- Version: 1.7.0
- Release date: Apr 26th, 2017

thank for help!

----Update----

I have new problem with product server. now I'm need to connect to a server version 2.8.5. And option "Enable WS/WSS" is on but my problem appear again
I tried to use Client API 1.7.1 and it can connect to server but there is no SFSObject in API, the document for SFSObject 's just work with Client API 1.7.0.
What can I do in this case?

Re: HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 08:32
by Lapo
Hi did you turn on the "Enable WS/WSS" option from the AdminTool > Server Configurator > Webserver?

Also:
I have tried to connect to server by pure Websocket API then successful, with SFS2X client, I get only the info below by all time and nothing else

What do you mean by "pure Websocket API"?

Thanks

Re: HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 08:46
by carbon_crystal
Thank for your response!
I just do your suggestion and it connected. :D :D
Sorry for "pure Websocket API", I mean I tried to connect without using SFS2X Client API.
Anyway, thanks again!

Re: HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 09:35
by carbon_crystal
Hi, I have new problem with product server. now I'm need to connect to a server version 2.8.5. And option "Enable WS/WSS" is on but my problem appear again
I tried to use Client API 1.7.1 and it can connect to server but there is no SFSObject in API, the document for SFSObject 's just work with Client API 1.7.0.
What can I do in this case?

Re: HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 10:03
by Lapo
It depends on which Javascript client API you're using.
You can see here: http://smartfoxserver.com/download/sfs2x#p=client
that we have two types of JS API. One with "binary protocol" and one without.

The binary JS API work with SFS2X 2.13 and higher. For any version lower than that (as in your case) you need to download and use the regular API.

Cheers

Re: HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 10:08
by carbon_crystal
Like I said, the regular API doesn't have SFSObject (am I wrong?), so I don't know how to add params for sending a custom command.

Code: Select all

TypeError: SFS2X.SFSObject is not a constructor


do you have an example about sending a command to server with the regular JS API?
Someting like this:

Code: Select all

var params = new SFS2X.SFSObject();
      params.putInt("zi", zoneId);
      params.putUtfString("ro", gameTableId);

      app.sfs.send(new SFS2X.ExtensionRequest("cmd", params));

Re: HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 13:13
by Lapo
Is there a specific reason to keep working with an outdated version such as 2.8? That's really old, lots of bug fixes and improvements have been added since then.

With our last release (2.13) we have improved our Javascript API and support for websockets and we're phasing out our old API. Unless there are specific constraints I'd highly recommend working with the new API.

Let us know.

Re: HTML Client API can't connect to server - hang at "Sending request 'HandshakeRequest' to server"

Posted: 28 Apr 2017, 13:16
by Lapo
Anyways, back to your question an example is found in the docs for the old API.
See here:
http://docs2x.smartfoxserver.com/api-do ... quest.html

thanks