How connect to server in WebGL

Hi guys!
I looked at several projects(created by Unity Tech), but I still did not understand how to connect some Match in WebGL. My steps:

  1. useWebSockets = true
  2. build for WebGL
  3. Run in editor and browser
  4. LAN Host in redactor and LAN client in browser. Its work
    What I want:
    1.Create match(in Editor or any possible Platform. I know that you cant lan host in WebGL, only connect)
    2.Find match in browser
    3.Connect

link to NetworkLobby Example from Unity tech(its like Tanks Example)

Someone can tell me how I can do it? (find and connect to internet match from WebGL).
Thanks in advance!

Their match maker doesn’t work with WebGL game. If you host a server in editor and tick the use websocket in network manager or set it true in NetworkServer and open the client in Firefox then it should work, On Edge and chrome you should use build and run for it to be hosted in a local web server to work.

Maybe I dont understand well. For example, I build WebGL project and run it on Firefox on my friend’s PC. I run server in Editor (LAN Host) on my PC. Then my friend try connect to server(using my IP), but nothing happens. When I try do the same at the same PC, its work nicely.

Briefly : computer1-computer1 = work nicely, but
computer1-computer2 = cant find/connect to match

How my friends can connect(WebGL) to my macth(Server in editor) ?

Aha , This is due to security issues.
You need a cross domain reference policy file which allows the connection to happen I guess. check the webGL part of the manual in relation to multiplayer.

1 Like

Thanks man! If it will work - you saved my life!! :):slight_smile: :wink:

Actually I was wrong, cross origin resource sharing seems to only apply to HTTP requests.
See the manual page related to it

In the coming days I should make this workin so can update you, if I forgot, send me a private message. I’m working on a cross mobile and WebGL multiplayer product so I have to make this work today or tomorrow and it should work.

Yeah, thank you!! I’ll look forward to.:slight_smile:

Did anything happen here?

Any solution? :hushed:
Just give me idea how I can connect to non-localhost ip address this thing. >_<
Browser : Chrome and Firefox
Host : github.io
Unity: 2017.2.0b5

@Danila24ru Your error is different to the error mentioned in the rest of the thread. The connection string you use in your unity scene should begin with “wss://” which indicates that you are trying to connect with SSL/HTTPS secured connection.

As for connecting to a non-local IP address/host, the problem you are encountering is related to CORS support, which is a built-in security functionality of most browsers. There are a couple of ways you can get around this:

  • You could start Chrome in insecure mode. This answer shows how to start in insecure mode.
  • You’ll need to update the server code to allow requests to come through from custom domains. or you can use third party servers that allow custom domains.

hi, i have the same problem, did you find a solution?

you found the solution ? Can you help me %

hello @danila24 did u found any solution?

Hello @parhamebi1 ,

If mofirouz’s answer didn’t solve your issue, please post a new thread into the WebGL section, you’ll have more chances of getting help.

Thanks!