ssl - Unity WebGL 中的 Photon 安全 WebSocket 连接

标签 ssl unity-game-engine websocket photon unity-webgl

当我尝试使用安全的 websocket 连接将本地 Photon 服务器与 Unity3D WebGL Build 连接时遇到问题。我可以建立与 websockets(不是安全的)和 WebGL 构建以外的任何其他环境的连接(即使在具有 WebGL 配置的 Unity 播放模式下,当我获得构建时它也不会工作)。我猜这个问题与我的证书有关,但我不完全确定。我试过自签名的,和真正的。

这里是错误:

enter image description here

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

我已经尝试过 127.0.0.1 而不是 localhost,尝试更改端口。

我从 Photon 的网站上获得了套接字代码,链接在这里:

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

我的客户端代码(使用 Photon 的 SocketWebTcp 类)是这样的:

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());
}}

这是 photon 服务器配置中应用程序的 websocket 监听器:

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

最后,这是我的自签名证书:

enter image description here

谢谢。

最佳答案

解决了这个问题,证书似乎不适用于像 127.0.0.1 这样的 IP 地址。证书需要一些地址(如 xxx.photon.com)

作为临时解决方案,可以向定义的 ip 发送 https 请求并插入 ip chrome 的允许 ips。此临时解决方案与此答案相关: https://stackoverflow.com/a/43493521/3013806

关于ssl - Unity WebGL 中的 Photon 安全 WebSocket 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44311792/

相关文章:

ios - 服务器未收到 MDM checkin 请求

java 签名 "hash values do not match"

c# - Unity3d 写入 Mac 上的文件路径访问被拒绝

ios - Xcode 中的构建错误。链接问题

java - Websocket 在连接时获取远程 IP

android - OkHTTP Websocket : Unexpected end of steam on Connection

internet-explorer - Internet Explorer 10 "This page cannot be displayed"加载我的网站时

unity-game-engine - 一个 Unity 实例,两个 Unity 窗口?

javascript - 帮助 android 到 chrome 通信

具有多个 SSL 证书的 Java 服务器