使用UnitySocketIO无法与wss://echo.websocket.org/握手

时间:2015-01-16 22:03:14

标签: c# unity3d websocket

我做基本的示例整合UnitySocketIO https://github.com/NetEase/UnitySocketIO/但是我收到错误,有人试图做?

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协议

1 个答案:

答案 0 :(得分:0)

尝试

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

RFC6455是最终的WebSocket标准规范。