Ozgur Yalcin
Ozgur Yalcin

Reputation: 55

Photon Secure WebSocket Connection In Unity WebGL

I'm having trouble when I try to connect my local Photon Server with Unity3D WebGL Build, using secure websocket connection. I can establish the connection with websockets (not the secure one) and any other environment other than WebGL builds (Even in Unity's play mode with WebGL configuration, it just won't work when I get a build). I'm guessing that the problem is related with my certificate but I'm not entirely sure. I tried self-signed one, and a real one.

Here is the error:

enter image description here

WebSocket connection to 'wss://localhost:19091' failed: Error in connection establishment: net::ERR_INSECURE_RESPONSE

I already tried 127.0.0.1 instead of localhost, tried to change the port.

I got my socket code from Photon's website, link is here:

https://www.photonengine.com/sdks#onpremiseunity3d

My Client code(uses Photon's SocketWebTcp class) is like this:

using ExitGames.Client.Photon;
using UnityEngine;

public class HiveClient : IPhotonPeerListener
{

    public PhotonPeer PhotonClient { get; set; }

    public HiveClient() { }

    public void Connect()
    {
        this.PhotonClient = new PhotonPeer(this, ConnectionProtocol.WebSocketSecure);
        this.PhotonClient.SocketImplementationConfig.Add(ConnectionProtocol.WebSocketSecure, typeof(SocketWebTcp));
        this.PhotonClient.Connect("wss://localhost:19091", "Hive");
    }

    public void DebugReturn(DebugLevel level, string message)
    {
        Debug.Log("DebugReturn: " + level.ToString() + " Message: " + message);
    }

    public void OnEvent(EventData eventData)
    {
        Debug.Log("OnEvent: " + eventData.Code);
    }

    public void OnOperationResponse(OperationResponse operationResponse)
    {
        Debug.Log("OnOperationResponse: " + operationResponse.DebugMessage);
    }

public void OnStatusChanged(StatusCode statusCode)
{
    Debug.Log("OnStatusChanged: " + statusCode.ToString());
}}

Here is app's websocket listener in photon server config:

<WebSocketListeners>
  <WebSocketListener IPAddress="0.0.0.0" Port="19091" DisableNagle="true" InactivityTimeout="10000" Secure = "true" StoreName = "MY" CertificateName = "DESKTOP-PQ845BC" UseMachineStore = "true">
  </WebSocketListener>
</WebSocketListeners>

Lastly, here is my self-signed certificate:

enter image description here

Thank you.

Upvotes: 0

Views: 3424

Answers (1)

Ozgur Yalcin
Ozgur Yalcin

Reputation: 55

Solved this, It seems certificates doesn't work with ip adresses like 127.0.0.1. Certificate expects some address (like xxx.photon.com)

As a temporary solution, one can send a https request to defined ip and insert the ip chrome's allowed ips. This temp solution relates to this answer: https://stackoverflow.com/a/43493521/3013806

Upvotes: 1

Related Questions