You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.4 KiB
63 lines
2.4 KiB
using Fleck;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Container.Common
|
|
{
|
|
public class ChatWebSocketMiddleware
|
|
{
|
|
//public static ConcurrentDictionary<string, System.Net.WebSockets.WebSocket> _sockets = new ConcurrentDictionary<string, System.Net.WebSockets.WebSocket>();
|
|
//public static List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>();
|
|
//static bool flag = true;
|
|
//private static Class_Log log = new Class_Log(); //日志记录文件
|
|
//private static App app = ((App)System.Windows.Application.Current);
|
|
//Thread receiveThread;
|
|
//public void openSocket()
|
|
//{
|
|
// try
|
|
// {
|
|
|
|
|
|
// FleckLog.Level = LogLevel.Debug;
|
|
// var ws = ConfigurationManager.AppSettings["websocketUrl"];
|
|
// var server = new WebSocketServer(ws);
|
|
// //RecognizerCLR.setBeamDir(serialPortname, microAngle);
|
|
// server.Start(socket =>
|
|
// {
|
|
// socket.OnOpen = () => //当建立Socket链接时执行此方法
|
|
// {
|
|
// //var data = socket.ConnectionInfo; //通过data可以获得这个链接传递过来的Cookie信息,用来区分各个链接和用户之间的关系(如果需要后台主动推送信息到某个客户的时候,可以使用Cookie)
|
|
// //Console.WriteLine("Open!");
|
|
// allSockets.Add(socket);
|
|
// ChatWebSocketMiddleware.allSockets.ToList().ForEach(s => s.Send(JsonConvert.SerializeObject(app.AppList)));
|
|
// };
|
|
|
|
// socket.OnClose = () =>// 当关闭Socket链接十执行此方法
|
|
// {
|
|
|
|
// //Console.WriteLine("Close!");
|
|
// allSockets.Remove(socket);
|
|
// };
|
|
|
|
// socket.OnMessage = message =>// 接收客户端发送过来的信息
|
|
// {
|
|
|
|
// };
|
|
// });
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
|
|
// log.WriteLogFile("异常了"+e.ToString(), "recorderror");
|
|
// }
|
|
|
|
//}
|
|
|
|
}
|
|
}
|
|
|