我做基本的示例整合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协议
答案 0 :(得分:0)
尝试
client = new Client(url, WebSocketVersion.Rfc6455);
RFC6455是最终的WebSocket标准规范。