onConnection if connection failed

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

FireSmartFox
Posts: 33
Joined: 28 Sep 2018, 19:47

onConnection if connection failed

Postby FireSmartFox » 22 Oct 2018, 17:13

Code: Select all

    var config = {};
    config.host = "100.200.100.200";
    config.port = "10024";
    config.useSSL = false;
   
     var sfs = new SFS2X.SmartFox(config);

     function onConnection(evtParams)
     {
         alert("test3");
         
         if (evtParams.success)
             console.log("Connected to SmartFoxServer 2X!");
         else
             console.log("Connection failed. Is the server running at all?");
     }
     function onConnectionLost(event)
     {
        alert("test2");
        console.log("Disconnection occurred; reason is: " + event.reason);
     }
     
     
     sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
     sfs.addEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost, this);

     sfs.connect();
     alert("test start");


The IP is invalid to test what happens if the connection can't be established.
Shouldn't be at least the event onConnection triggered?
Just "test start" is displayed on page load.
The console doesn't show errors except "[ SFS2X | ERROR ] Invalid TCP connection port: 10024".
FireSmartFox
Posts: 33
Joined: 28 Sep 2018, 19:47

Re: onConnection if connection failed

Postby FireSmartFox » 22 Oct 2018, 18:35

Wow.

It was because the port was in "" and read as a string.

Code: Select all

config.port = 10024;

If written like that, all events are working.

Took a lot of time to find it out. :?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: onConnection if connection failed

Postby Lapo » 22 Oct 2018, 19:20

Yeah, the port value must be a number.
Unfortunately Javascript is very loose with types. When in doubt I'd recommend checking the docs. For example the constructor of the SmartFox class provides all the details for each parameter:
http://docs2x.smartfoxserver.com/api-do ... rtFox.html

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 20 guests