Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity.Network any plans in WebGL?

Discussion in 'WebGL' started by greggtwep16, Mar 29, 2015.

  1. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    Can anyone from Unity comment on if there are any plans to support the unity networking classes in WebGL at any point? I realize even among the other platforms not all targets support Unity's networking classes (windows phone for example) I'm just looking for a statement either way on whether or not there are any plans to do so.

    Developers might want to develop a webrtc asset on the store if there are no current plans for webgl networking so I figured Id ask.
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,647
    UnityEngine.Networking (which is based on RakNet) will never be supported on WebGL.

    The reason is that RakNet relies on direct access to TCP/UDP Sockets which is not possible in WebGL (and will never be due to security concerns).

    Unity 5.1 will (most likely) ship our upcoming new networking library UNET (which will make UnityEngine.Networking deprecated), which will support WebGL (via a WebSocket brigde) out of the box.

    Other options:

    -Build a wrapper for WebSockets or WebRTC yourself (examples have been posted to this forum).

    -Use an existing third party library which wraps WebSockets (SmartFoxServer or Photon).
     
  3. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    Thanks for the detailed reply Jonas!

    I realize 5.1's UNET isn't out yet but since for WebGL it's built on websockets it will require a relay server correct? Just want to double check that for LAN based products (like the asset in my signature) there would be no way around needing to go out to the internet and back for something on the LAN using UNET on the webgl target. Well I guess technically a server could be on the LAN but that isn't prudent for most users of the asset.

    I'm pretty sure the answer is no and it's understandable I just wanted to verify.
     
  4. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,647
    Yes, it will require a relay server (which UNET will provide), so correct, it would not work for a local LAN setup without requiring setting up a UNET server. But then, if you host games on a web server to run with WebGL, an internet connection can sort of be assumed (i guess Chromebooks in offline mode might be an exception).

    For direct networking between clients, you'd need to use WebRTC. gfoot on this forum posted a wrapper to do that. However, unlike WebSockets, not all browsers support WebRTC yet.
     
  5. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    WebRTC requires exchanging a few hundred bytes each way to establish a connection, then is peer-to-peer after that. It doesn't specify how the handshake is exchanged - usually websockets are used, but you could for example connect two mobile phones by having each take a photo of a QR code displayed on the other. That would work for a PC too if it had a webcam, but doesn't really work as a general solution.
     
  6. K-z3

    K-z3

    Joined:
    Aug 19, 2012
    Posts:
    1,671
    Is Unity planning to have a Cloud Based Networking Service like Photon? Or do we still have to host our own servers with UNet? As I understood it previously the older Unity Networking Solution did provide a Master Server I think for us to connect to, but it was not designed to be used in production, just more for testing. Is that the same idea your planning to do with UNet, just provide a test server, but we still need to host our own after?
     
  7. that-steve-guy

    that-steve-guy

    Joined:
    Apr 21, 2013
    Posts:
    15
    If anyone is looking for a partner/client with a bit of funding for multiuser WebGL work in Unity, I've got a university related research project in need of a hand with the networking side. - sguynup@aii.edu
     
  8. K-z3

    K-z3

    Joined:
    Aug 19, 2012
    Posts:
    1,671
    Check your Email.
     
  9. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    Are there any updates regarding this topic? I just want to use components like NetworkManager or NetworkAnimators in a WebGL application. Is this possible with UNET?
     
  10. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,647
    Yes, this is possible. This thread is old and was referring to our old networking system. The new networking tech (NetworkManager or NetworkAnimators) should be supported, but may need some configuration to use WebSockets which enable it in WebGL. @Marco Trivellato may be able to comment on how to set it up?
     
  11. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    That is great. I'm always getting this error:

    Failed running C:\Program Files\Unity\Editor\Data\Tools/UnusedByteCodeStripper2/UnusedBytecodeStripper2.exe -out "E:\Repositories\WebDevelopment\Unity\LOP\Temp\StagingArea\Data\Managed\tempStrip" -l none -c link -x "C:\Program Files\Unity\Editor\Data\Tools\native_link.xml" -f "C:\Program Files\Unity\Editor\Data\il2cpp\LinkerDescriptors" -x "E:\Repositories\WebDevelopment\Unity\LOP/Temp/StagingArea/Data/methods_pointedto_by_uievents.xml" -d "E:\Repositories\WebDevelopment\Unity\LOP\Temp\StagingArea\Data\Managed" -a "E:\Repositories\WebDevelopment\Unity\LOP\Temp\StagingArea\Data\Managed\Assembly-CSharp-firstpass.dll" -a "E:\Repositories\WebDevelopment\Unity\LOP\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" -a "E:\Repositories\WebDevelopment\Unity\LOP\Temp\StagingArea\Data\Managed\UnityEngine.Networking.dll"

    stdout:
    Fatal error in Mono CIL Linker
    System.Exception: Error processing method: 'System.Boolean UnityEngine.Networking.NetworkServer::InternalListen(System.String,System.Int32)' in assembly: 'UnityEngine.Networking.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Int32 UnityEngine.Networking.NetworkTransport::AddHost(UnityEngine.Networking.HostTopology,System.Int32,System.String)
    at Mono.Linker.Steps.MarkStep.MarkMethod (Mono.Cecil.MethodReference reference) [0x00000] in <filename unknown>:0
    at Mono.Linker.Steps.MarkStep.MarkInstruction (Mono.Cecil.Cil.Instruction instruction) [0x00000] in <filename unknown>:0
    at Mono.Linker.Steps.MarkStep.MarkMethodBody (Mono.Cecil.Cil.MethodBody body) [0x00000] in <filename unknown>:0
    at Mono.Linker.Steps.MarkStep.ProcessMethod (Mono.Cecil.MethodDefinition method) [0x00000] in <filename unknown>:0
    at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00000] in <filename unknown>:0
    --- End of inner exception stack trace ---
    at Mono.Linker.Steps.MarkStep.ProcessQueue () [0x00000] in <filename unknown>:0
    at Mono.Linker.Steps.MarkStep.Process () [0x00000] in <filename unknown>:0
    at Mono.Linker.Steps.MarkStep.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
    at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
    at Mono.Linker.Driver.Run () [0x00000] in <filename unknown>:0
    at Mono.Linker.Driver.RunDriver (Mono.Linker.Driver driver) [0x00000] in <filename unknown>:0
    stderr:

    UnityEngine.Debug:LogError(Object)
    UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:66)
    UnityEditorInternal.AssemblyStripper:RunAssemblyLinker(IEnumerable`1, String&, String&, String, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:192)
    UnityEditorInternal.AssemblyStripper:StripAssembliesTo(String, String, String&, String&, String, String, IEnumerable`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:185)
    UnityEditorInternal.AssemblyStripper:Strip(String, String, String&, String&, String, String, IEnumerable`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:136)
    UnityEditorInternal.AssemblyStripper:Strip(String[], String[], String, String, String&, String&, String, String, IEnumerable`1) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:121)
    UnityEditorInternal.IL2CPPBuilder:RunAssemblyStripper(IEnumerable, String, String[], String[], String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:441)
    UnityEditorInternal.IL2CPPBuilder:StripAssemblies(IEnumerable`1, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:414)
    UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:291)
    UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:218)
    UnityEditor.HostView:OnGUI()

    And I thought this error occurs because Networking is not supported in WebGL. But maybe my configuration is wrong?

    Thank you for your reply!
     
  12. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    This was fixed a few patches ago. Could you please try to use Unity 5.2.2 ?

    To use UNET in WebGL, you just need to enable NetworkInfo=>useWebSockets in your NetworkLobbyManager component.

    Just be aware that you cannot host games on the WebGL side, you can only join existing games.
     
  13. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    Sadly I still have problems to achieve my goal.
    I have activated the "use websockets" checkbox in the NetworkManager (not the NetworkLobbyManager). And build my project for windows as standalone. Now I want to choose the "LAN Host" or "LAN Server Only" option in the default HUD. Sadly the following error message occurs:
    And when I'm trying to build the WebGL application and running the index.html, I'm getting the following error in the console:
    Here you can see my configuration of the NetworkManager:

     
  14. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    - is this with Unity 5.2.2 ?
    - could you please post the stacktrace from a Development Mode build ?

    Please re-upload the image
     
  15. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    Yes this is with Unity 5.2.2.

    Stacktrace:
    Furthermore I attached the image to this message. networkmanager.jpg
     
  16. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Chances are it is the same problem reported in this other thread, which we already fixed in 5.3

    Could you please try to add a dummy script with an empty OnGUI method to any of the game objects in the scene ?
     
  17. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    Yes it works! Thanks a lot for this! Now I want my WebGL client to connect to a windows standalone server. If I enable the "use websockets" checkbox in the NetworkManager, the following error appears when I run the exe and press the "LAN Host" button:
    If I disable the "use websocket" checkbox for the windows standalone, the WebGL client cannot connect to the standalone server, because he is not using websockets.
     
  18. Paradoks

    Paradoks

    Joined:
    Oct 13, 2009
    Posts:
    429
  19. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    screen.jpg It works now. Here are my settings of the network manager. I wonder which option did the job ...
     
  20. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    114
  21. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    Hello,

    I have one additional question: If I want to start a network application, is it always necessary to host the game with a standalone? Or is (or will) it be possible to host a game via WebGL or WebPlayer? Or is this not possible because of the restrictions of the JavaScript language?
     
  22. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    On Unity WebGL you cannot host, you need to do that on Standalone (or in the Editor for testing).

    Basically web sockets (or webrtc) do not allow listen sockets, so we can't create a game a wait other players to join.

    The alternative solution would be to use a relay server. We do provide that service and WebGL support will be added in the future (but we don't have an ETA yet).
     
  23. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    Thank you for your answer! The same is true for WebPlayer?
     
  24. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    I am not quite sure honestly but be aware that we are dropping support for the WebPlayer.
     
  25. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
    Could someone explain what exactly the relay server is? I'm googling around, but I cannot find something satisfying.
     
  26. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    it's a sort of intermediary between clients. There is a bit of info here.
     
  27. PfcGarcia

    PfcGarcia

    Joined:
    Aug 27, 2013
    Posts:
    17
    Hi Marco,

    I'm trying to run "Network Game Lobby (beta)" v1.3 from Unity sample projects in WebGL but I'm receiving the following error in console: "Could not open file sharedassets0.assets.resS for read".

    Is there any example project known to see how UNet is working as a client in WebGL?
    Thanks!
     
  28. PhilippLe

    PhilippLe

    Joined:
    Sep 10, 2015
    Posts:
    28
unityunity