gpt4 book ai didi

c# - 无法与 wss ://echo. websocket.org/with UnitySocketIO 握手

转载 作者:太空宇宙 更新时间:2023-11-03 15:46:15 25 4
gpt4 key购买 nike

我做了基本示例,将 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);
}

}

输出是:

Error initializing handshake with wss://echo.websocket.org/

我试过 ws 和 wss 协议(protocol)

最佳答案

尝试

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

RFC6455 是最终的 WebSocket 标准规范。

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com