Page 1 of 1

Client not connecting

Posted: 19 Jan 2025, 20:46
by Riotlove
Hello. I'm currently working on an educational site using the javascript API. There are no errors, but it says its unable to connect to the server. When I try to connect, it makes a session, but it's unable to connect.

Re: Client not connecting

Posted: 20 Jan 2025, 07:02
by Lapo
Hi,
is the server online or local?
If it's online make sure that port 8080/8443 are reachable (i.e. not blocked by a firewall)

Let us know

Re: Client not connecting

Posted: 20 Jan 2025, 18:15
by Riotlove
Local. And i'm able to connect using other forms for my other server.

Re: Client not connecting

Posted: 21 Jan 2025, 07:12
by Lapo
Can you show the code used for connecting to the server and the transcription of the error from the browser's console?
Also please specify which server version you're using and which Client API version,
(client API version is found by printing out the SmartFox.getVersion() method)

Thanks

Re: Client not connecting

Posted: 22 Jan 2025, 12:39
by Riotlove
Heres my code:

Code: Select all

// Create configuration object
var config = {};
config.host = "127.0.0.1";
config.port = 9933;
config.debug = true;
config.useSSL = false;

// Create SmartFox client instance
sfs = new SFS2X.SmartFox(config);

// Set logging
sfs.logger.level = SFS2X.LogLevel.DEBUG;
sfs.logger.enableConsoleOutput = true;
sfs.logger.enableEventDispatching = true;

// Add event listeners
sfs.addEventListener(SFS2X.SFSEvent.CONNECTION, onConnection, this);
sfs.addEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost, this);

// Attempt connection
sfs.connect();

function onConnection(event) {
    if (event.success) {
        console.log("Connected to SmartFoxServer 2X!<br>SFS2X API version: " + sfs.version);

        // Show disconnect button
        switchButtons();
    } else {
        console.log("Connection failed: " + (event.errorMessage ? event.errorMessage + " (" + event.errorCode + ")" : "Is the server running at all?"));

        // Reset
        reset();
    }
}

function onConnectionLost(event) {
    console.log("Disconnection occurred; reason is: " + event.reason);
    // Reset
    reset();
}

function reset() {

    // Remove SFS2X listeners
    sfs.removeEventListener(SFS2X.SFSEvent.CONNECTION, onConnection);
    sfs.removeEventListener(SFS2X.SFSEvent.CONNECTION_LOST, onConnectionLost);

    sfs = null;
}

function loginToSmartFox(username, password) {
    var zoneName = "Worko";
    sfs.login(zoneName, username, password);
}

and it just says something generic (I haven't tested it in a few days) like unable to connect to webserver ws://127.0.0.1

Re: Client not connecting

Posted: 22 Jan 2025, 18:22
by Lapo
Hi,
the code looks good.
SFS2X uses port 8080 for HTTP traffic. This could be an issues if you're already running another http/web server that already uses that port.

In any case, I would recommend a simple test. Start SFS2X, then open a browser and connect to http://127.0.0.1:8080

Does it work? Do you see the welcome page?

Thanks

Re: Client not connecting

Posted: 24 Jan 2025, 12:32
by Riotlove
I'm able to go to localhost:8080. And i'm able to configure my other zone, too. Oddly when I try to connect using my site it makes a session according to the smartfox log

Re: Client not connecting

Posted: 24 Jan 2025, 15:54
by Lapo
Sorry, but something escaped my eye.
Only now I notice you use this:

Code: Select all

config.port = 9933;

which is incorrect. Websocket connection happens on port 8080, so you need:

Code: Select all

config.port = 8080;


Cheers

Re: Client not connecting

Posted: 24 Jan 2025, 23:07
by Riotlove
tysm