Connection Error

Post here your questions about the HTML5 / JavaScript for SFS2X

Moderators: Lapo, Bax

username55
Posts: 5
Joined: 20 Mar 2013, 09:58

Connection Error

Postby username55 » 20 Mar 2013, 10:40

Hi,

First of all i am not sure whether i should post this on the server side or on the client side. I just have a hunch that this is a client side problem.

My Server version:

SFS2x Ver. 2.6.0

This is my current server configuration (i leave everything as default):

IP: 127.0.0.1
Socket: 9933

Websocket listener is set to its default setting:

127.0.0.1 : 8888

The problem that i am having is every time i would like to access the GameLobby via:

127.0.0.0:8080/GameLobby

It shows me the login page, however i am unable to connect (by pressing the connect button).
I received the following error:

ATTENTION(S)
Connection failed: Is the server running at all?

event.errorMessage() returns with an "undefined" message.

looking at main.js, specifically on the onConnectBtClick() (source as below)

Code: Select all

function onConnectBtClick()
{
   // Connect to SFS
   // As no parameters are passed, the config object is used
      sfs.connect();
   
      // Hide any previous error
      $("#errorLb").hide();
   
      // Disable button
      enableButton("#connectBt", false);
}


Do i need to explicitly set the client so it open a websocket to the said port (which is 127.0.0.1:8888)

I modified the code below to this:

Code: Select all

function onConnectBtClick()
{
   // Connect to SFS
   // As no parameters are passed, the config object is used
   ws.onopen = function(){
      sfs.connect();
   
      // Hide any previous error
      $("#errorLb").hide();
   
      // Disable button
      enableButton("#connectBt", false);
   }
}


where ws is:

Code: Select all

var ws = new WebSocket("ws://127.0.0.1:8888");


however i still have no luck.

Could any one give me a hint? am i missing something here?

thank you for the help.

edited: I already made sure that JS is enabled on my browser.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Connection Error

Postby Bax » 20 Mar 2013, 11:53

Hello.
First of all you don't need to manually open a websocket connection, as this is done by the API internally.
I did the following test and everything works as expected:

1) copied the GameLobby example folder to SFS2X/www/root
2) opened the example using the url localhost:8080/GameLobby
3) clicked the connect button
4) on connection clicked the login button

If the same doesn't work for you, the HTML5 support might be disabled in your configuration.
Open the AdminTool's Server Configurator and go to the HTML5 WebSockets tab.
Make sure the protocol is activated. If not, activate it and restart the server.
In the startup log you should read

Code: Select all

12:29:55,662 INFO  [main] v2.SmartFoxServer     - Listening Sockets: { 127.0.0.1:9933, (Tcp) } { 127.0.0.1:9933, (Udp) } { 127.0.0.1:8888 (WebSocket) }

right before the SFS2X READY message.
Paolo Bax
The SmartFoxServer Team
username55
Posts: 5
Joined: 20 Mar 2013, 09:58

Re: Connection Error

Postby username55 » 20 Mar 2013, 14:22

[img][img]Hi Bax,

Thanks for the reply.

Wierdly i did exatcly those step you mention. In fact, let me share my store until i get this kind of error.

1. I downloaded and installed SFS2x Community Edition (ver. 2.0.x) from the download page (x64 version, since i am running x64 bit of Win 7).

2. Once installation completed, i immediatel run the server. I faced a small hiccups, mostly due to my firewall. With my firewall re-configured i ran the server. Everything ran normally.

3. I downloaded some example packs from the Example tab (Flash pack, Unity Pack and HTML5 pack).
4. I put all the pack in the /www/[root_dir] within the installation directory, and reconfigured the necessary XML file (mostly making sure that the IP of my server instance is correct).

5. Play around with all the examples, both locally (using the same machine to test the multiplayer as well as using totally different machine [my laptop]). I did have some trouble with the AvatarChat, at first i did not load correctly (the circle thingy at the bottom right keep showing me red lights). After a while, i noticed that the version of my flash player on my laptop is different (older version). So i went to get the latest version of my flash player, and tested it one more time.

This time it works... i can see the other avatar (the one on the PC) from my laptop.

6. Tested the unity example package, it worked perfectly.

7. Sadly though, the story is a bit different with HTML5. First, i thought because ver 2.0.1 haven't support HTML5 (Socket in particular). So i went on to the update page to get the latest version.

8. I unpacked everything, and run the *.bat file.
9. Turned out the *.bat file open the *.jar file.
10. The self-updater *.jar given me error (access denied). This is obvious, since i installed it on my Program Files/.../...

11. After reading the error line carefully, i decided to go on and update it manually, by copied the necessary files & directory to the location as specified by the *.jar.

12. I run the server, everything went normal. The server is running the latest version 2.6.x
13. I tested the example package again (flash, unity, HTML5). Everything went well apart from the websocket.

14. In the server confgurator i double checked everything including those you mention above:

- websocket option (enabled)
- port i used for the server to listen to the websocket 8808, 8080 (this one failed for obvious reason), 8008.

Everytime go to the login page of GameLobby and click on the connect, it appears that the client is trying to reach the server. As indicated by the console window of SFS2x, the server responded to this call. However, when it reached the onConnection() method (refer to the main.js) it always goes to the else { } clause.

printing event.errormessage() does not help at all, since it only returns "undefined" as a message.

I even get the same log message on the console mentioning that the server is listening to the websocket port i mentioned.

I am currently not in front of my computer right now. But, i'll give it another try using different PC.
username55
Posts: 5
Joined: 20 Mar 2013, 09:58

Re: Connection Error

Postby username55 » 20 Mar 2013, 14:26

by the way, another thing i should mention

i used this to access those examples:

192.168.1.102:8080/Example_Packages/ (from within my LAN)

and/or

127.0.0.1:8080/Example_Packages

all worked but websocket.

In the server configurator, i added:

127.0.0.1 (both for UDP/TCP) and 192.168.1.102 (both UDP/TCP) - all using 9933

as the address and the socket, the instance should listen to.
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Connection Error

Postby Bax » 20 Mar 2013, 15:54

username55 wrote:- port i used for the server to listen to the websocket 8808, 8080 (this one failed for obvious reason), 8008.

By default the client connects via websocket using port 8888. If you changed it the the above values, you also have to configure the SmartFox instance passing the right port number.
Paolo Bax
The SmartFoxServer Team
huhailong
Posts: 28
Joined: 14 May 2010, 04:39

Re: Connection Error

Postby huhailong » 22 Mar 2013, 03:37

you should change main.js config.host = "192.168.1.102"; then it will be ok.
username55
Posts: 5
Joined: 20 Mar 2013, 09:58

Re: Connection Error

Postby username55 » 26 Mar 2013, 12:37

Bax wrote:
username55 wrote:- port i used for the server to listen to the websocket 8808, 8080 (this one failed for obvious reason), 8008.

By default the client connects via websocket using port 8888. If you changed it the the above values, you also have to configure the SmartFox instance passing the right port number.


Hi

Sorry for the slow response. I believe i have tried that as well.
Even worse this time, somehow i get no response at all.

Here is my screenshot. I might as well re-install it.

Console Log (indicates all required ports are available and ready).
Image

main.js
Image

This is what i got, when i tried to connect.
Image

General & Web Socket Panel
Image
Image

Am i missing something?

All antivirus and/or firewall completely off.


@huhailong

i've tried that as well. But still no luck :(
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Connection Error

Postby Bax » 26 Mar 2013, 15:01

In your main.js the port number is wrong.
As the html5 API use websockets for connection, you have to use port 8888.
Paolo Bax
The SmartFoxServer Team

Return to “SFS2X HTML5 / JavaScript API”

Who is online

Users browsing this forum: No registered users and 53 guests