Trying to connect to via websockets using Unity WebGL adds /websocket...

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Trying to connect to via websockets using Unity WebGL adds /websocket...

Postby Ninjaoninja2 » 05 Mar 2020, 03:51

Hi there,

I'm experimenting with websockets with Unity's WebGL Builds, and I cannot connect to my server running SmartFox, my server has an SSL setup and SmartFox is set to only accept secure incoming connections, which is why I'm trying to use the WSS protocol, but out of curiosity I tried using just the normal WS protocol as well, just to check if maybe trying to connect using WSS was the problem, no luck, neither seem to work. The connection attempt seems to add /websocket to each request, which returns a 404, since /websocket doesn't exist on my server. (Ex: ws://mydomain.com:8080/websocket or wss://mydomain.com:8443/websocket)

I have setup the connection according to the docs, the only differences include, removing 8080, and just using 8443, and changing UseWebSocket.WS_BIN to UseWebSocket.WSS_BIN for the secure connection, since my SmartFox config only accepts secure connections.

The docs mentioned not using initCrypto in regards to websockets, so I'm not using it, but I'm not sure if not using that in this case is affecting the connection? Honestly though, I'm just assuming it's the 404, I'm not sure how to remove the /websocket at the end of the domain though, am I supposed to? Maybe I've set things up incorrectly?

If you need more information let me know.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Trying to connect to via websockets using Unity WebGL adds /websocket...

Postby Lapo » 05 Mar 2020, 15:02

Hi.
yes we need more info.
For starters what SFS2X version you're using and what Unity API version you're running in your code.

Before testing with SSL, let's try a simple non-encrypted connection.
Step #1, make sure you can reach the server at port 8080 via your browser (http://www.yourdomain.com:8080)
Step #2, make sure Websocket is active from the AdminTool > Server Settings > Web Server.

Try testing both from the Unity editor and the built client and let us know.

Last but not least, keep an eye for CORS (cross-origin resource sharing) errors when testing in the browser. For example if you're loading the game from the local file system you will likely incur in that issue.

If you're testing in the browser and the connection fails, check the browser's error console and tell us what error(s) did you get.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Ninjaoninja2
Posts: 204
Joined: 22 Sep 2013, 23:33

Re: Trying to connect to via websockets using Unity WebGL adds /websocket...

Postby Ninjaoninja2 » 07 Mar 2020, 23:30

Lapo wrote:Hi.
yes we need more info.
For starters what SFS2X version you're using and what Unity API version you're running in your code.

Before testing with SSL, let's try a simple non-encrypted connection.
Step #1, make sure you can reach the server at port 8080 via your browser (http://www.yourdomain.com:8080)
Step #2, make sure Websocket is active from the AdminTool > Server Settings > Web Server.

Try testing both from the Unity editor and the built client and let us know.

Last but not least, keep an eye for CORS (cross-origin resource sharing) errors when testing in the browser. For example if you're loading the game from the local file system you will likely incur in that issue.

If you're testing in the browser and the connection fails, check the browser's error console and tell us what error(s) did you get.

Thanks


I have tried to reach port 8080, it connects just fine, Websocket is already active. I am using the latest SFS2X Version (2.15) and the latest C# API (1.7.13). For a little clarification, the 404 error is from the broswers console.

Code: Select all

WebSocket connection to 'wss://mydomain.com:8443/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404
and when using 8080...

Code: Select all

WebSocket connection to 'ws://mydomain.com:8080/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404


I am running this on a web server, and have tested from the build client. Because I am just looking to export for WebGL, It won't operate in the Unity Editor.

Thanks.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Trying to connect to via websockets using Unity WebGL adds /websocket...

Postby Lapo » 08 Mar 2020, 09:48

It sounds like your current installation might be corrupted.
Please download SFS2X 2.14.0 from here --> https://www.smartfoxserver.com/download#p=installer

Remove the previous installation, or install a new copy in a different location on your machine/server.
Then try again: it should work without any issues.
Once it's done you can apply patch 2.15

Let us know.
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 34 guests