Can't connect to server - after update client to v1.7.2

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

reshevskiy_is
Posts: 4
Joined: 15 May 2017, 09:00

Can't connect to server - after update client to v1.7.2

Postby reshevskiy_is » 15 May 2017, 12:54

Hi, I'm using React JS. Before updating everything worked perfectly. But after updating

- Client API to v1.7.2
- Smartfoxserver 2X to v2.13

I have trouble. When I have tried to connect to server, I get this in console

Code: Select all

[ SFS2X | INFO ] SmartFox instance ready
[ SFS2X | INFO ] SFS2X JavaScript API v1.7.2
[ SFS2X | INFO ] Attempting connection to server
[ SFS2X | INFO ] Sending request 'HandshakeRequest' to server

sfs2x-api-1.7.2.js:10 Uncaught RangeError: Wrong length!
    at validateArrayBufferArguments (_typed-buffer.js:157)
    at new ArrayBuffer (_typed-buffer.js:247)
    at SFSDataSerializer.object2binary (sfs2x-api-1.7.2.js:9)
    at SFSObject.toBinary (sfs2x-api-1.7.2.js:11)
    at SFSProtocolCodec.onPacketWrite (sfs2x-api-1.7.2.js:10)
    at SocketEngine.send (sfs2x-api-1.7.2.js:10)
    at SmartFox.send (sfs2x-api-1.7.2.js:8)
    at SmartFox._onSocketConnect (sfs2x-api-1.7.2.js:8)
    at SocketEngine.dispatchEvent (sfs2x-api-1.7.2.js:10)
    at WebSocket._onSocketConnect (sfs2x-api-1.7.2.js:10)


This is my code

Code: Select all

var sfs = null;

class Map extends React.Component {

    constructor(props) {
        super(props);

        var config = {};

        config.host = "127.0.0.1";
        config.port = 8080;
        config.zone = "BasicExamples";
        config.debug = true;

        sfs = new SFS2X.SmartFox(config);

        var platform = navigator.appName;
        var version = navigator.appVersion;

        sfs.setClientDetails(platform, version);
        sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, this.onConnection, this);

        sfs.connect();
    }
   
   function onConnection(event) {
         if (event.success) {
            console.log("Connected to SmartFoxServer 2X!");
         } else {
            alert("Failed!");
         }
      }
}


thank for help!
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can't connect to server - after update client to v1.7.2

Postby Lapo » 15 May 2017, 13:52

Hi,
I assume you're using the new Javascript API with binary protocol, right?
If so have activated the websocket binary protocol on server side? For compatibility reasons we have added a switch to specify which API you're using

See attached image.
protocol-websocket.png
(36.48 KiB) Not downloaded yet

To change settings go to AdminTool > Server Configurator > Web server

thanks
p.s. more on this here -> http://docs2x.smartfoxserver.com/Gettin ... ration-213
Lapo
--
gotoAndPlay()
...addicted to flash games
reshevskiy_is
Posts: 4
Joined: 15 May 2017, 09:00

Re: Can't connect to server - after update client to v1.7.2

Postby reshevskiy_is » 15 May 2017, 14:14

Yes, I use using the new Javascript API with binary protocol and I activated the websocket binary protocol
Here are my server settings

Pasted image at 2017_05_15 05_08 PM.png
settigs
(31.88 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can't connect to server - after update client to v1.7.2

Postby Lapo » 15 May 2017, 14:49

Config looks good.
Try connecting to the server, and see what happens in the server logs.

Do you see any errors? Does the "Session created" message appear in the logs? Is there more data?

Also are you connecting via WS or WSS?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
reshevskiy_is
Posts: 4
Joined: 15 May 2017, 09:00

Re: Can't connect to server - after update client to v1.7.2

Postby reshevskiy_is » 15 May 2017, 15:45

I connecting via WS.

These are server logs

Code: Select all

15 May 2017 | 18:31:53,537 | INFO  | qtp348055829-42 | bitswarm.sessions.DefaultSessionManager |     | Session created: { Id: 1874, Type: WEBSOCKET, Logged: No, IP: 192.168.10.xxx } on Server port: 8889 <---> 61143

15 May 2017 | 18:32:28,759 | INFO  | qtp348055829-40 | bitswarm.sessions.DefaultSessionManager |     | Session removed: { Id: 1874, Type: WEBSOCKET, Logged: No, IP: 192.168.10.xxx:61143 }


If I make a connection without React - connection is error-free, but in the previous version Client API everything worked fine with React(

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

Re: Can't connect to server - after update client to v1.7.2

Postby Lapo » 15 May 2017, 16:38

reshevskiy_is wrote:If I make a connection without React - connection is error-free, but in the previous version Client API everything worked fine with React(

I see. I am not familiar with React at all, but from what you're saying it seems as if React is messing around with websockets. :shock:
Not sure how, though. In particular I can't imagine how it can make the connection fail, unless (as I am supposing) it kind of messes with the basic websocket classes... or something like that?

Can you show me how your connection code looks like with ReactJS?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
reshevskiy_is
Posts: 4
Joined: 15 May 2017, 09:00

Re: Can't connect to server - after update client to v1.7.2

Postby reshevskiy_is » 16 May 2017, 08:32

I fixed this problem by changing the version Client API to the previous one and disabled "Use WS binary protocol" in the admin panel.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Can't connect to server - after update client to v1.7.2

Postby Bax » 16 May 2017, 09:07

This is a temporary workaround, but we would like to understand why the API doesn't work with ReactJS.
Could you provide a proof of concept, showing just the basic connection and login, so we can investigate the issue?
Thank you.
Paolo Bax
The SmartFoxServer Team
etonev777
Posts: 40
Joined: 08 Jan 2014, 08:21

Re: Can't connect to server - after update client to v1.7.2

Postby etonev777 » 07 Jun 2017, 13:06

Hi i am using ANgular2 and have exact same problem. The server settings are good. Here is what i get in the browser:

[ SFS2X | INFO ] Attempting connection to server
sfs2x-api-1.7.3.js:12859 [ SFS2X | INFO ] Sending request 'HandshakeRequest' to server
errors.ts:42 ERROR RangeError: Wrong length!
at Z (shim.js:5552)
at new ArrayBuffer (shim.js:5642)
at SFSDataSerializer.object2binary (sfs2x-api-1.7.3.js:4468)
at SFSObject.toBinary (sfs2x-api-1.7.3.js:5594)
at SFSProtocolCodec.onPacketWrite (sfs2x-api-1.7.3.js:5398)
at SocketEngine.send (sfs2x-api-1.7.3.js:5287)
at SmartFox.send (sfs2x-api-1.7.3.js:3158)
at SmartFox._onSocketConnect (sfs2x-api-1.7.3.js:3211)
at SocketEngine.dispatchEvent (sfs2x-api-1.7.3.js:5042)
at WebSocket._onSocketConnect (sfs2x-api-1.7.3.js:5296)

You can check the shim.js file it is available in the net.
Can you please assist us to solve this problem and use the new api?!
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Can't connect to server - after update client to v1.7.2

Postby Bax » 07 Jun 2017, 13:31

We have investigated this issue, and unfortunately it is caused by Angular itself (or more likely by one of its many dependancies - we suspect core-js).
In fact that "shim.js" changes the default behavior of the native JavaScript ByteArray, making it impossible to create an array without specifying its length (which is a feature needed by our API). There's no easy fix to this, which would require a major rework on our API go work around this unintelligible choice (why change the default behavior of native objects?!?!).
Our suggestion is to stick with the text protocol, as reshevskiy_is said above.
Paolo Bax
The SmartFoxServer Team
etonev777
Posts: 40
Joined: 08 Jan 2014, 08:21

Re: Can't connect to server - after update client to v1.7.2

Postby etonev777 » 08 Jun 2017, 15:39

You said it by yourself. This is not a solution. Besides the modern apps on the web are using frameworks such as Angular and React, nobody is writing anymore a serious app without framework. In the new age without Flash you need one of those to create a good browser app. So it seems a little bit useless this new Binary Protocol for JS.
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can't connect to server - after update client to v1.7.2

Postby Lapo » 08 Jun 2017, 16:06

What is not clear is why Angular, via some of its components, is breaking the behavior of a core Javascript class, i.e. ArrayBuffer.
According to Mozilla's doc ArrayBuffer are supported by all major browsers and it's not even a recent thing.
https://developer.mozilla.org/it/docs/W ... ped_arrays

So are all the current browser's implementations broken and only Angular knows better, or is it the other way around. Or both?
At the moment I can't find any evidence in support of all current implementations being broken.

Have you got any insights?
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
etonev777
Posts: 40
Joined: 08 Jan 2014, 08:21

Re: Can't connect to server - after update client to v1.7.2

Postby etonev777 » 08 Jun 2017, 16:38

Maybe for older or mobile browsers. I don't know.
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can't connect to server - after update client to v1.7.2

Postby Lapo » 09 Jun 2017, 08:42

I can't find anything that supports the idea that ArrayBuffers are broken in current browsers. In fact typed arrays are green-lighted in all major browsers: http://caniuse.com/typedarrays/embed/stats=none

In any case I think there should be a workaround to stop Angular from complaining.
But we need to run some tests first. We'll keep you posted.
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Can't connect to server - after update client to v1.7.2

Postby Bax » 09 Jun 2017, 12:40

etonev777, we further investigated the issue as Lapo reported, and we think we have a fix.
Send us an email at info -AT- smartfoxserver -DOT- com, so we can send you a pre-release version to try out.
Thanks.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 19 guests