当我尝试使用安全的 websocket 连接将本地 Photon 服务器与 Unity3D WebGL Build 连接时遇到问题。我可以建立与 websockets(不是安全的)和 WebGL 构建以外的任何其他环境的连接(即使在具有 WebGL 配置的 Unity 播放模式下,当我获得构建时它也不会工作)。我猜这个问题与我的证书有关,但我不完全确定。我试过自签名的,和真正的。
这里是错误:
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>
最后,这是我的自签名证书:
谢谢。
最佳答案
解决了这个问题,证书似乎不适用于像 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/