Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

SocketIO Library not working in WebGL built. But no Errors in sight?

Discussion in 'WebGL' started by Chazin, May 12, 2021.

  1. Chazin

    Chazin

    Joined:
    Apr 27, 2021
    Posts:
    3
    Hello there,

    I recently started working on a unity WebGL project and ran into a problem with the built version.
    There is some network code involved but since everything is working within the editor I figured the problem has to lie within the way my WebGL application is built.

    I am using Node.js and Socket.IO on the sever-side and also a corrseponding plugin in the Unity client.

    The Socket.IO Client can be found here: https://github.com/dp0ch/Unity-SocketIO-Client

    I appended some Debug.Log functions into the Socket Code to find out where everything is failing.

    the problem I face is the debug.log messages are not even fired in the build version of my application.
    furthermore there are no signs of any connection on my server. It seems like any code of that Socket.IO library is simply ignored.
    Worst part is, there are no errors or anything pointing me in the general direction of the problem.

    However when I run the application in the Unity editor everything is working as expected and my server is registering a connection.
    I also see the debug.log messages that you would expect in the Browser aswell.

    Maybe there is something wrong with my build & run options for WebGL?
    Maybe there is somewhere else where I can look for errors?

    I will attach some screenshots for clarification:

    Use of the library and appending some debug.log messages when even trying to connect somewhere



    View of the application in the Editor


    View of the application in the built WebGL player


    Build settings:


    I am thankful for any Input on this matter

    kind regards
     
  2. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    277
    The image is too small.
     
  3. Chazin

    Chazin

    Joined:
    Apr 27, 2021
    Posts:
    3
    You are totally right how could I miss that..

    let me try again:






     
  4. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    277
    Project Settings > Player > Publishing Settings > Enable Exceptions = Full Width(out) Stacktrace
    Build Settings > Development Build ☑
     
    Last edited: May 13, 2021
  5. Chazin

    Chazin

    Joined:
    Apr 27, 2021
    Posts:
    3
    Thanks for the Input. Unfortunately no Exceptions or Errors were visible.

    However in my research i stumbled upon this Chapter in Unitys Documentation:

    https://docs.unity3d.com/Manual/webgl-networking.html
    Due to security implications, JavaScript code does not have direct access to IP Sockets to implement network connectivity. As a result, the .NET networking
    classes (ie, everything in the System.Net namespace, particularly System.Net.Sockets) are non-functional in WebGL
    . The same applies to Unity’s old UnityEngine.Network* classes, which are not available when building for WebGL.


    A closer look at the plugin I used from https://github.com/dp0ch/Unity-SocketIO-Client
    reveals the dependency on WebSocketSharp: https://github.com/sta/websocket-sharp

    right there on their frontpage in github it also states:

    It works with Unity Free, but there are some limitations:

    The server is not available in Web Player
    WebGL Networking Not available in WebGL



    so in conclusion: It simply cannot work. What a bummer. Now I gotta try and write my own Websocket method and maybe I can replace the websocketSharp part in the SocketIO-Client Library... lets see where this goes..
     
    DoDius likes this.
  6. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    944
    Web browsers do unfortunately not give access to native sockets. The author of SocketIO library should offer a web version of their client plugin that accesses Websockets JS API, instead of attempting to use native sockets.

    Btw there is an upcoming "WebTransport" specification which enables "native-like" sockets in browsers. While still not a direct native access to sockets (for security reasons), it will have the ability to do more capable socket communications than what WebSockets is able to provide.
     
  7. G3nko0

    G3nko0

    Joined:
    Oct 1, 2016
    Posts:
    12