Hi, folks! ✌️ How are you? 👋

I'm working on the game that uses WebSocketPeer for multiplaying.

And when I runs the game, WebSocketPeer works as well. Also when I exports the game for Desktop platforms, then launches this, WebSocketPeer works also.

The problems happens when I exports the game for WebGL:

  1. I export the game for WebGL, compress this to a zip archive, then send this archive to the VPS server.

  2. Connect to this VPS server and unzip archive.

From a browser the game works very well, except connection through WebSocketPeer.

For running this game on a browser, I'm using NGINX as a HTTP server.

This game connect to the game server (that developed separately), that also located on the same machine, and also uses WebSocketPeer.

I have try to point the IP address of the VPS server in the configs of the game, and it doesn't works. Also doesn't works to point "127.0.0.1" in the configs of this game.

Folks, where's the problem may be? And what do I do wrong now? 😟

Thanks in advance.

you are viewing a single comment's thread
view the rest of the comments
[–] 1 point 11 months ago (4 children)

I don't have experience with web sockets in godot but I do have experience in web development

I assume it's because you are hosting the game from somewhere other than where you are trying to connect.

A look at this article should help. https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS#examples_of_access_control_scenarios

You'll need to send some extra headers that will allow the browser to connect to it.

I think this one? https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS#access-control-allow-origin

I only ever set it to * and forgot about it when I have done API development.

I hope this is helpful!

  • source
  • hideshow 4 child comments
  • [–] [S] 1 point 11 months ago

    Thanks to you, @nobody_special 🤝

    But I already guessed where's the problem was be.

    https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content

    If it said shortly, I needed to add to the IP address for a connection (for example 192.168.0.150), one of the name of the secure protocols (wss://, https://, etc.) (result: wss://192.168.0.150/)

    So, I think that I'm in one step closer to the solution.

    Now the developer consoles seems somehow like that:

    But the game still doesn't works.

    Thanks for your help, again 🤝

  • source
  • parent
  • [–] [S] 1 point 11 months ago (2 children)

    Now the game awaits pending, but then shows "CONNECTION_TIMEOUT".

  • source
  • parent
  • hideshow 2 child comments
  • [–] 1 point 11 months ago* (1 child)

    I think it might be helpful to understand the flow from a high level to help you further. Because right now I'm bit confused on the ordering / actors involved and what the difference between what is supposed to happen and what is happening.

    Doesn't have to be a great diagram. Something shitty like this diagram below.

  • source
  • parent
  • hideshow 1 child comment
  • [–] [S] 1 point 11 months ago

    Don't pay attentions on the quality, the meaning is important here. It's a normal diagram.

    And, yeap! The game's webserver (nginx) locates in the same VPS where locates the game's APIs. So, a browser loads the game's client (WebGL version of the game) from the same place, where in the next step, after loading has finished, this browser will connects to that place for connection to the game's APIs.

  • source
  • parent