我做了基本示例,将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标准规范。

关于c# - 无法使用UnitySocketIO与wss://echo.websocket.org/握手,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27993517/

10-09 20:00