Search Unity

Resolved websocket-sharp runtime error after WebGL build

Discussion in 'Multiplayer' started by unitsume, May 9, 2023.

  1. unitsume

    unitsume

    Joined:
    Oct 7, 2022
    Posts:
    31
    Hello.

    I'm creating a system that uses websocket-sharp to communicate with a server.
    It worked fine in the Unity editor but gave an error in the browser after the WebGL build.
    Do you know how to solve it?
    If my information is missing, please contact me.

    Thank you.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using WebSocketSharp;
    5.  
    6. public class TestWS : MonoBehaviour
    7. {
    8.     private WebSocket ws;
    9.  
    10.     private void Start()
    11.     {
    12.         ws = new WebSocket("ws://xxx.xxx.xxx.xxx:xxxxx");
    13.  
    14.         ws.OnOpen += (sender, e) =>
    15.         {
    16.             Debug.Log("WebSocket connected");
    17.             ws.Send("Hello server!");
    18.         };
    19.  
    20.         ws.OnMessage += (sender, e) =>
    21.         {
    22.             Debug.Log("Received message: " + e.Data);
    23.         };
    24.  
    25.         ws.OnClose += (sender, e) =>
    26.         {
    27.             Debug.Log("WebSocket closed");
    28.         };
    29.  
    30.         ws.Connect();
    31.     }
    32.  
    33.     private void OnDestroy()
    34.     {
    35.         if (ws != null && ws.IsAlive)
    36.         {
    37.             ws.Close();
    38.         }
    39.     }
    40. }

    error messages

    websocket_build.loader.js:1
    exception thrown: RuntimeError: null function or function signature mismatch,RuntimeError: null function or function signature mismatch
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[24860]:0x6ba9d2
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[24855]:0x6ba473
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[751]:0x36028
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[963]:0x3e9ff
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[18603]:0x524cae
    at invoke_viiii (http://localhost:61228/Build/websocket_build.framework.js.gz:3:343679)
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[2443]:0xa04c0
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[1257]:0x52609
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[18606]:0x524ce2
    at invoke_viii (http://localhost:61228/Build/websocket_build.framework.js.gz:3:343150)
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[11959]:0x3ed975
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[11937]:0x3eb341
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[24853]:0x6ba3f9
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[24326]:0x6adf7c
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[4518]:0x14b595
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[18609]:0x524d0a
    at invoke_iiii (http://localhost:61228/Build/websocket_build.framework.js.gz:3:343510)
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[924]:0x3c80c
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[8648]:0x280096
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[616]:0x262d3
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[2404]:0x9d088
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[22880]:0x64b3c6
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[21760]:0x5ee971
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[20761]:0x577e23
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[10980]:0x37cf4f
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[10980]:0x37cfbe
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[10064]:0x2f1e87
    at http://localhost:61228/Build/websocket_build.wasm.gz:wasm-function[18601]:0x524c8c
    at browserIterationFunc (http://localhost:61228/Build/websocket_build.framework.js.gz:3:212816)
    at callUserCallback (http://localhost:61228/Build/websocket_build.framework.js.gz:3:166141)
    at Object.runIter (http://localhost:61228/Build/websocket_build.framework.js.gz:3:167401)
    at Browser_mainLoop_runner (http://localhost:61228/Build/websocket_build.framework.js.gz:3:165676)

    websocket_build.framework.js.gz:3
    Uncaught RuntimeError: null function or function signature mismatch
    at websocket_build.wasm.gz:0x6ba9d2
    at websocket_build.wasm.gz:0x6ba473
    at websocket_build.wasm.gz:0x36028
    at websocket_build.wasm.gz:0x3e9ff
    at websocket_build.wasm.gz:0x524cae
    at invoke_viiii (websocket_build.framework.js.gz:3:343679)
    at websocket_build.wasm.gz:0xa04c0
    at websocket_build.wasm.gz:0x52609
    at websocket_build.wasm.gz:0x524ce2
    at invoke_viii (websocket_build.framework.js.gz:3:343150)
    at websocket_build.wasm.gz:0x3ed975
    at websocket_build.wasm.gz:0x3eb341
    at websocket_build.wasm.gz:0x6ba3f9
    at websocket_build.wasm.gz:0x6adf7c
    at websocket_build.wasm.gz:0x14b595
    at websocket_build.wasm.gz:0x524d0a
    at invoke_iiii (websocket_build.framework.js.gz:3:343510)
    at websocket_build.wasm.gz:0x3c80c
    at websocket_build.wasm.gz:0x280096
    at websocket_build.wasm.gz:0x262d3
    at websocket_build.wasm.gz:0x9d088
    at websocket_build.wasm.gz:0x64b3c6
    at websocket_build.wasm.gz:0x5ee971
    at websocket_build.wasm.gz:0x577e23
    at websocket_build.wasm.gz:0x37cf4f
    at websocket_build.wasm.gz:0x37cfbe
    at websocket_build.wasm.gz:0x2f1e87
    at websocket_build.wasm.gz:0x524c8c
    at browserIterationFunc (websocket_build.framework.js.gz:3:212816)
    at callUserCallback (websocket_build.framework.js.gz:3:166141)
    at Object.runIter (websocket_build.framework.js.gz:3:167401)
    at Browser_mainLoop_runner (websocket_build.framework.js.gz:3:165676)

    websocket_build.framework.js.gz:3
    An abnormal situation has occurred: the PlayerLoop internal function has been called recursively. Please contact Customer Support with a sample project so that we can reproduce the problem and troubleshoot it.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,998
    Make sure you run a development build with all debugging features turned on, such as exception handling and full stacktraces.The given error message is not helpful so you need to get more info from the build.
     
  3. unitsume

    unitsume

    Joined:
    Oct 7, 2022
    Posts:
    31
    Thank you.
    I will try.
     
  4. unitsume

    unitsume

    Joined:
    Oct 7, 2022
    Posts:
    31
    I checked "Development Build" in "Build Settings".
    I checked "Full" in "Project Settings" > "Stack Trace".
    But the error did not change.
    Am I missing a setting?
    My Unity editor version is "2021.3.11f1".

    unity1.png
    unity2.png
     
  5. priyanshusaininew

    priyanshusaininew

    Joined:
    Apr 26, 2023
    Posts:
    1
    Does it Solved
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    WebSocket-sharp does not export (in a working condition) to WebGL.
    You need a JS library to integrate the browser WebSocket API for Unity.