2017-06-01 145 views
0

我嘗試使用安全websocket連接將我的本地Photon服務器與Unity3D WebGL構建連接時出現問題。我可以建立與websockets(不是安全的)和除了WebGL之外的任何其他環境的連接(即使在Unity的具有WebGL配置的播放模式下,當我獲得構建時,它也不會工作)。我猜這個問題與我的證書有關,但我不完全確定。我嘗試了自簽名的,而且是真正的。Photon Secure WebSocket連接在Unity WebGL

以下是錯誤:

enter image description here

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

我已經嘗試過127.0.0.1而不是本地主機,試圖改變端口。

我得到了我的插座代碼光子的網站,鏈接在這裏:

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

我的客戶代碼(採用光子的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()); 
}} 

這裏是應用程序的網頁套接字聽衆在光子服務器配置中:

<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

謝謝。

回答

1

解決了這個問題,似乎證書不能用於ip地址,如127.0.0.1。證書需要一些地址(如xxx.photon.com)

作爲一個臨時解決方案,可以發送https請求到定義的ip並插入ip chrome的允許的ips。此臨時解決方案與此答案相關: https://stackoverflow.com/a/43493521/3013806