Search Unity

System.Net.WebSockets usage in WebGL builds

Discussion in 'Web' started by ufmsp, Nov 23, 2017.

  1. ufmsp

    ufmsp

    Joined:
    Oct 3, 2017
    Posts:
    11
    Hello all,


    We're currently testing a managed dll plugin for WebGL builds, which relies on the System.Net.WebSockets library for doing WebSocket communication. I have been testing the System.Net.WebSockets library myself for WebGL builds (using Unity 2017.3.0b10) in order to investigate whether it works or not, and I'm getting mixed results. Here are my findings:

    - Code DOES build for WebGL when using the System.Net.WebSockets namespace.
    - It CAN instantiate a ClientWebSocket at runtime.
    - When I call connectAsync then the socket DOES change state from 'None' to 'Connecting'.

    BUT, I see NO outgoing network traffic at all (using Wireshark) after calling connectAsync and I get NO errors/warnings at all in the log.

    My question is : Is System.Net.WebSockets expected to work in WebGL builds?

    Or must we use https://www.assetstore.unity3d.com/en/#!/content/38367 in order to get WebSockets to work?

    Thanks a lot in advance for all help.


    Kind regards,
    Uffe Flarup
     
    adamkis likes this.
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    I assume you are referring to System.Net.Sockets.

    As per this page, everything in the System.Net namespace is not supported. You can use the asset store package you mentioned to build your networking layer or use a 3rd party library.
     
  3. ufmsp

    ufmsp

    Joined:
    Oct 3, 2017
    Posts:
    11
    Thanks for your quick reply. I actually WAS referring to System.Net.WebSockets and not System.Net.Socket (we're using the Experimental .NET 4.6 scripting backend).

    But since everything under System.Net is not supported on WebGL it doesn't change a whole lot :)

    We'll investigate alternatives...
     
  4. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,166
    Does `System.Net.WebSockets` work on all other platform? iOS? Android?

    If it is I think we could make easy wrapper that would use js WebSocket only for WebGL
     
    goldbug and VOTRUBEC like this.