Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question Changing the source does not change the build result.

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

  1. unitsume

    unitsume

    Joined:
    Oct 7, 2022
    Posts:
    31
    Hello.

    I once did a WebGL build with the wrong source.
    I changed the source and did a WebGL build again.
    However, the content of the error does not change.
    Does Unity have a cache or something?
    Do you have any idea?

    Thank you.

    Console Error

    WebSocket connection error: DOMException: Failed to construct 'WebSocket': The URL 'ws://xxx.xxx.xxx.2206:xxxxx' is invalid.
    at _WebSocketConnectA (http://localhost:49673/Build/build.framework.js:3:69377)
    at http://localhost:49673/Build/build.wasm:wasm-function[25286]:0x90d342
    at http://localhost:49673/Build/build.wasm:wasm-function[25284]:0x90d322
    at http://localhost:49673/Build/build.wasm:wasm-function[53760]:0x117dba0
    at http://localhost:49673/Build/build.wasm:wasm-function[52270]:0x114472d
    at http://localhost:49673/Build/build.wasm:wasm-function[10552]:0x31eeeb
    at http://localhost:49673/Build/build.wasm:wasm-function[41794]:0xe01d17
    at invoke_iiii (http://localhost:49673/Build/build.framework.js:3:390009)
    at http://localhost:49673/Build/build.wasm:wasm-function[1868]:0x9b62c
    at http://localhost:49673/Build/build.wasm:wasm-function[22201]:0x726dc7
    at http://localhost:49673/Build/build.wasm:wasm-function[907]:0x6bada
    at http://localhost:49673/Build/build.wasm:wasm-function[5549]:0x184735
    at http://localhost:49673/Build/build.wasm:wasm-function[50158]:0x10cd47f
    at http://localhost:49673/Build/build.wasm:wasm-function[45588]:0xee44e2
    at http://localhost:49673/Build/build.wasm:wasm-function[44608]:0xe788e3
    at http://localhost:49673/Build/build.wasm:wasm-function[24000]:0x87c8ea
    at http://localhost:49673/Build/build.wasm:wasm-function[24000]:0x87c95b
    at http://localhost:49673/Build/build.wasm:wasm-function[21179]:0x6802f6
    at http://localhost:49673/Build/build.wasm:wasm-function[41786]:0xe01c99
    at browserIterationFunc (http://localhost:49673/Build/build.framework.js:3:225456)
    at callUserCallback (http://localhost:49673/Build/build.framework.js:3:178654)
    at Object.runIter (http://localhost:49673/Build/build.framework.js:3:179914)
    at Browser_mainLoop_runner (http://localhost:49673/Build/build.framework.js:3:178189)
    _WebSocketConnectA @ build.framework.js:3


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class TestWS4 : MonoBehaviour
    7. {
    8.  
    9.     [SerializeField]
    10.     //private string url = "ws://xxx.xxx.xxx.2206:xxxxx";
    11.     private string url = "ws://xxx.xxx.xxx.206:xxxxx";
    12.  
    13.     [DllImport("__Internal")]
    14.     private static extern void WebSocketConnectA(string url);
    15.  
    16.     [DllImport("__Internal")]
    17.     private static extern void WebSocketSendA(string data);
    18.  
    19.     [DllImport("__Internal")]
    20.     private static extern void WebSocketCloseA();
    21.  
    22.     [DllImport("__Internal")]
    23.     private static extern void WindowAlert(string str); // window.alert()
    24.  
    25.     private void Start()
    26.     {
    27.         Connect();
    28.  
    29.     }
    30.  
    31.     private void Update()
    32.     {
    33.         if (Input.GetKey("w"))
    34.         {
    35.             Send("test");
    36.         }
    37.     }
    38.  
    39.     public void Connect()
    40.     {
    41.         WebSocketConnectA(url);
    42.     }
    43.  
    44.     public void Send(string data)
    45.     {
    46.         WebSocketSendA(data);
    47.     }
    48.  
    49.     public void Close()
    50.     {
    51.         WebSocketCloseA();
    52.     }
    53.  
    54.     public void OnWebSocketConnected()
    55.     {
    56.         WindowAlert("WebSocket connected");
    57.     }
    58.  
    59.     public void OnWebSocketReceived(string message)
    60.     {
    61.         WindowAlert("Unity WebSocket received: " + message);
    62.     }
    63.  
    64.     public void OnWebSocketClosed()
    65.     {
    66.         WindowAlert("WebSocket closed");
    67.     }
    68.  
    69. }
    Code (JavaScript):
    1. mergeInto(LibraryManager.library, {
    2.   ws: null,
    3.  
    4.   WebSocketConnectA: function(urlPtr) {
    5.     try {
    6.       // Convert the pointer to a string
    7.       var url = UTF8ToString(urlPtr);
    8.  
    9.       // WebSocket connection process
    10.       this.ws = new WebSocket(url);
    11.  
    12.       // WebSocket open event handler
    13.       this.ws.onopen = function(event) {
    14.         // Call WebSocket connection success event on the Unity side
    15.         myGameInstance.SendMessage("GameObject", "OnWebSocketConnected");
    16.       };
    17.  
    18.       // WebSocket message event handler
    19.       this.ws.onmessage = function(event) {
    20.         // Call WebSocket receive event on the Unity side
    21.         myGameInstance.SendMessage("GameObject", "OnWebSocketReceived", event.data);
    22.       };
    23.  
    24.       // WebSocket close event handler
    25.       this.ws.onclose = function(event) {
    26.         // Call WebSocket close event on the Unity side
    27.         myGameInstance.SendMessage("GameObject", "OnWebSocketClosed");
    28.       };
    29.  
    30.       // WebSocket error event handler
    31.       this.ws.onerror = function(event) {
    32.         console.error("WebSocket error: ", event);
    33.       };
    34.     } catch (error) {
    35.       console.error("WebSocket connection error: ", error);
    36.     }
    37.   },
    38.  
    39.   WebSocketSendA: function(data) {
    40.     try {
    41.       // WebSocket data sending process
    42.       this.ws.send(UTF8ToString(data));
    43.     } catch (error) {
    44.       console.error("WebSocket send error: ", error);
    45.     }
    46.   },
    47.  
    48.   WebSocketCloseA: function() {
    49.     try {
    50.       // WebSocket closing process
    51.       this.ws.close();
    52.     } catch (error) {
    53.       console.error("WebSocket close error: ", error);
    54.     }
    55.   },
    56.  
    57.   WindowAlert: function (str) {
    58.     window.alert(UTF8ToString(str));
    59.   },
    60.  
    61.   ConsoleLog: function (str) {
    62.     console.log(str);
    63.   },
    64.  
    65. });
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Try clearing the browser cache, or run it in a different browser.

    Make sure to delete the build folder and the folder on the webserver (if you upload it) to make sure you are doing a clean build/install.
     
  3. unitsume

    unitsume

    Joined:
    Oct 7, 2022
    Posts:
    31
    Thank you.
    I tried those methods. But the execution result was the same.
    Are there other factors affecting it?
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Well maybe you didn‘t change the code in a way that fixes the issue? ;)
    Maybe it‘s as simple as accidentally uploading the wrong build. Check what happens if you do Build & Run.