39 lines
996 B
C#
39 lines
996 B
C#
using BestHTTP.WebSocket;
|
|
using EasyInject.Attributes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 用于管理WebSocket通信
|
|
/// </summary>
|
|
|
|
[Component]
|
|
public class WebSocketManage
|
|
{
|
|
/// <summary>
|
|
/// 创建websocket通信
|
|
/// </summary>
|
|
/// <param name="url">地址</param>
|
|
/// <param name="callBack">消息回调</param>
|
|
/// <param name="errorBack">通信异常回调</param>
|
|
public WebSocket CreateWebSocket(string name, string url,OnWebSocketMessageDelegate callBack,OnWebSocketErrorDelegate errorBack)
|
|
{
|
|
WebSocket webSocket = new WebSocket(new Uri(url));
|
|
webSocket.OnMessage += callBack;
|
|
webSocket.OnError += errorBack;
|
|
webSocket.Open();
|
|
return webSocket;
|
|
}
|
|
public WebSocket CreateWebSocket(string name, string url)
|
|
{
|
|
WebSocket webSocket = new WebSocket(new Uri(url));
|
|
webSocket.Open();
|
|
return webSocket;
|
|
}
|
|
public void AddMessageEvent()
|
|
{
|
|
|
|
}
|
|
}
|