Hi everyone and if this is a noob question, i’m getting started with unity so sorry in advance.
I’m trying to make a webgl multiplayer project that it is uploaded (hosted) into a vps (ubuntu), and it can be executed from a browser.
And the goal of my project is to have the client and server running only in webgl (it could be different projects, but both must be running on webgl), but I’m having dificulties in understanding how i can make the server of my project running on webgl, because based of what i saw in the internet, the server could only be executed in unity editor or windows/linux application (not in webgl), but since i’m using a vps based on ubuntu i’m hoping that is a chance to make server work on webgl.
I searched in google for answers and for example this package of webrtc isnt compatible with webgl:
Mirror isnt a solution either because it isnt compatible with webgl because of kcp transport (not sure if it is the only reason):
I also found the page below, but i’m not sure if it is the answer to my problem (basically i dont know if websockets are the only problem with this server/webgl problem):
This is not possible. If a web app - any web app - would be able to enable other remote participants (users or apps) to join their “service” in any way, then it would be a MASSIVE security issue for the entire worldwide web.
To that end, Web Browsers execute WebGL apps in a sandbox. And within that sandbox an app isn’t allowed to receive incoming connections. Therefore no other external services can “join” a web app.
At least that’s my understanding.
Anyway, you don’t need the WebGL app to also host. At least I could think of no reason why running the server on the same platform than the clients would be of any benefit. You wouldn’t run a server on a mobile phone either.
Since you have to run the server on a machine that is remotely accessible, you make the server app an app for that machine’s OS, most likely Linux but could also be Windows but you do pay more for Windows hosting.
Thank you for your time and very good answer, that was really nice!
So to make it totally clear to me, if i create a linux/windows server project (server app) and make it run on a vps (for example) i could connect webgl only as client or even this is impossible because of the reason that web browsers execute webgl apps in a sandbox?
Photon offers what’s called a Relay Service, which allows clients to find a game that is being hosted by a Master Client, then connects all the clients together. Clients are not really connected to the master client directly, as the Relay Service is handling the connectivity and relaying all the required network messages to all clients. Although there is a-lot of risk with this approach.
Poor Gameplay Experience Due to Increase of Latency through Relay and depending on a Master Client (acting as a server) that could have poor internet connection, or not very good computer specs.
Hacking & cheating is impossible to prevent because the Master Client can modify the entire state of the game at any time effecting all other clients.
I’ve created a game like this before, and I can tell you it’s not worth it! So I’d certainly would suggest exploring building a WebGL Game with Dedicated Server w/ Mirror or whatever other networking solution you like.
Feel free to join me on Discord, I recently started a Unity WebGL Multiplayer Game Developers Discord to help support developers like yourself. Discord
As far as I know using WebRTC instead of WebSocket should allow client hosting. I’m aware that Coherence has implemented this kind of approach for WebGL but they don’t support p2p yet. I’m also aware of an experimental Mirror transport that uses WebRTC but that has only been used on desktop platforms and lacks support for relay fallback.
I’m surprised that WebRTC on WebGL hasn’t been utilized more.