无法通过 UnitySocketIO wss://echo.websocket.org/ 握手



我做了将 UnitySocketIO https://github.com/NetEase/UnitySocketIO/与 Unity 集成的基本示例,但我得到一个错误,有人试图这样做?

using UnityEngine;
using System.Collections;
using SocketIOClient;
using WebSocket4Net;
public class WsConnection : MonoBehaviour {
    Client client;
    string url = "wss://echo.websocket.org";
    // Use this for initialization
    void Start () {
        client = new Client(url, WebSocketVersion.DraftHybi00);
        client.Opened += SocketOpened;
        client.Message += SocketMessage;
        client.SocketConnectionClosed += SocketConnectionClosed;
        client.Error +=SocketError;
        client.Connect();
    }
    private void SocketOpened(object sender, System.EventArgs e) {
        //invoke when socket opened
        client.Send("hello world");
    }
    private void SocketMessage (object sender, MessageEventArgs e) {
        if ( e!= null && e.Message.Event == "message") {
            string msg = e.Message.MessageText;
            //process(msg);
            Debug.Log(msg);
            client.Close();
        }
    }
    private void SocketConnectionClosed(object sender, System.EventArgs e) {
        //invoke when socket opened
        Debug.Log("Conexion cerrada...");
    }

    private void SocketError(object sender, System.EventArgs e) {
        //invoke when socket opened
        Debug.Log(((SocketIOClient.ErrorEventArgs)e).Message);
    }
}

输出是:

使用 wss://echo.websocket.org/初始化握手时出错

我尝试过使用 ws 和 wss 协议

试试

client = new Client(url, WebSocketVersion.Rfc6455);

RFC6455是最终的WebSocket标准规范。

相关内容

  • 没有找到相关文章

最新更新