Search Unity

Unity Networking and WebGL

Discussion in 'Multiplayer' started by ElnuDev, Jul 28, 2018.

  1. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    How do I create a server in WebGL? When I start up the WebGL version of the game, I get this:
    upload_2018-7-27_16-34-48.png
    Is WebGL networking even possible?
     
  2. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    18
    Enable "Use WebSockets" in Network Manager.
     
    ElnuDev likes this.
  3. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    It still doesn't let me create a server or use match maker.
     
  4. YuriPetskus

    YuriPetskus

    Joined:
    Jun 22, 2018
    Posts:
    18
    WebGL version cannot be server.
    Run one Windows instance as server. Then WebGL-instance can connect to server as client.
     
    ElnuDev likes this.
  5. ElnuDev

    ElnuDev

    Joined:
    Sep 24, 2017
    Posts:
    298
    Thanks mate! I got it to work. :D
     
  6. koalagamesnl

    koalagamesnl

    Joined:
    Sep 13, 2017
    Posts:
    1
    i dont understand what you mean Yuri
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    WebGL cannot act as a server. Use a Windows or other standalone platform build as the server. By default Unet on all platforms other than WebGL will use UDP for Unet's network transport, but WebGL is not capable of using UDP, only Websockets. So you tell the standalone build to use Websockets instead of UDP so WebGL clients can talk to it.

    https://docs.unity3d.com/ScriptReference/Networking.NetworkManager-useWebSockets.html
     
    ElnuDev and YuriPetskus like this.
  8. Sheezuu

    Sheezuu

    Joined:
    Oct 24, 2018
    Posts:
    8
    kindly tell me how to set multiplayer using WebGL ?? i upload webGL build on Domain(Server) and try to play multiplayer game by running two instances on different laptops but it didnt work for me both players cant find each other. Kindly help
     
  9. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    You don't mention a game server they're connecting to...do you have one? Are they both able to connect to it?
     
    Joe-Censored likes this.
  10. Sheezuu

    Sheezuu

    Joined:
    Oct 24, 2018
    Posts:
    8
    i upload the build file on server and both players open the file but they cant find each other please help me
     
  11. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    368
    There isn't any magic - you still need a game server hosted somewhere for both players to connect to. It sounds like you've created a single player game with no networking and no game server.
     
  12. Sheezuu

    Sheezuu

    Joined:
    Oct 24, 2018
    Posts:
    8
    I mention the server IPaddress in Network Manager Still it didnt make connection between two clients
     
  13. Sheezuu

    Sheezuu

    Joined:
    Oct 24, 2018
    Posts:
    8
    If u help me it will be very honourable for me
     
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You need a SERVER

    You will not be able to "make connection between two clients". You need a standalone build (not WebGL, instead Windows/Linux/Mac, etc) set up to act as a server which the two clients connect to. You will also need to make sure the server build is set to use websockets.
     
    Last edited: Jan 25, 2019
  15. Sheezuu

    Sheezuu

    Joined:
    Oct 24, 2018
    Posts:
    8
    using PC/Windows/Linux it works well but i want to Make i webGL -_- it didnt work . Do u have any idea ??
     
  16. Sheezuu

    Sheezuu

    Joined:
    Oct 24, 2018
    Posts:
    8
    nd i want to upload my game on domain(server) and make two clients to connect with each other. Any idea how to do ??
     
  17. Sheezuu

    Sheezuu

    Joined:
    Oct 24, 2018
    Posts:
    8
    am getting this issue on executing webgl html page "Uncaught TypeError: Cannot read property ‘id’ of null "
    plz help me to solve this
     
  18. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    WebGL uses websockets, you'd have to configure your standalone server build to use websockets instead of UDP in order for the WebGL build to be able to connect to it.
     
  19. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Clients don't connect to each other, period. Not sure if you're meaning something different, or don't understand how it works, but the clients in order to affect each other will do so through their connection to the same server.
     
  20. massey_digital

    massey_digital

    Joined:
    Apr 28, 2013
    Posts:
    94
    Wanted to add to this thread that the aforementioned websocket process worked for me, but I had to use Firefox instead of Edge in order for it to work. I'm using 2019.3.0a7, and auto graphics api which when I turn off goes to WebGL 2.0.. I believe this means that it also won't work with IE and I am using Chrome 75 which also didn't work.
     
  21. Anpu23

    Anpu23

    Joined:
    Sep 4, 2017
    Posts:
    16
    So I am still trying to wrap my head around all of this. I own a third party independent virtual server, I've successfully loaded and played single party games on it using WebGL. Now I want to try multiple party games hosted and ran on the website without a need for the client to download anything. In other words log on, click on the game and run from the website directly.
     
  22. Walter_Hulsebos

    Walter_Hulsebos

    Joined:
    Aug 27, 2015
    Posts:
    46