Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question WebGL on WSS connection: Failed to construct 'WebSocket'

Discussion in 'Game Server Hosting' started by salavideoclase7, Mar 8, 2024.

  1. salavideoclase7


    Jul 8, 2022
    I'm developing a multiplayer game with a WebGL client that connects to a Linux server with Unity Game Hosting platform (Multiplay).

    My WebGL Client is hosted through HTTPS so, I get this error:

    The page at 'https://......' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://3X.XX.XX.XXX:9000/'. This request has been blocked; this endpoint must be available over WSS.

    It is as if the client, by default, is using ws and not wss to connect to the server.

    I believe that the server side (Unity Multiplay) is correctly configurated. In the log I don't get any clue of the connection type (ws or wss).

    By the way, I don't get any error when I try from localhost (http not https) with xampp.

    So, is there any special configuration when building the WebGL client? (or maybe in its hosting? I'm using BanaHosting (shared), which works fine with Gzip or Brotli without fallback with some warnings)? Or when building the server executable?

    Or in the code when starting client or server?

    I am using this method for both client and server, passing the IpAddress and Port:

    Code (CSharp):
    2. ServerConfig serverConfig = MultiplayService.Instance.ServerConfig;
    4. NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(serverConfig.IpAddress, serverConfig.Port, "");
    6. NetworkManager.Singleton.StartServer();
    Code (CSharp):
    2. NetworkManager.Singleton.GetComponent<UnityTransport>().SetConnectionData(_ipAddressField.text, ushort.Parse(_portField.text));
    4. NetworkManager.Singleton.StartClient();
    And this is my Unity Transport configuration. For both it is the same (server and client):

    And by the way, this is the log of my test allocation:

    Code (Log):
    2. StartServer
    4. ServerConfig:
    5. ServerId: 690X290X
    6. AllocationId: 6a6f592X-cbc6-4fXd-8c24-fX15cb4cdXb8
    7. IpAddress: 3X.9X.1XX.1XX
    8. Port: X000
    9. QueryPort: X010
    10. LogDirectory: /mnt/unity/logs/
    12. StartServerQueryHandlerAsync
    13. SQP server: SQP server started on
    15. [Netcode] StartServer
    16. [Netcode] Initialize

    I hope you can help me and that it can be useful for others who have the same problem. Thanks in advance!