using System.Security.Cryptography.X509Certificates; using Fleck; namespace SupperWebSocket { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private WebSocketServer _webSocketServer; private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if (button1.Text == "开启Socket服务") { string location = "wss://0.0.0.0:8181"; _webSocketServer = new WebSocketServer(); _webSocketServer.Start(location); button1.Text = "关闭WebSocket"; timer1.Interval = 2000; timer1.Start(); } else { button1.Text = "开启Socket服务"; _webSocketServer.Stop(); timer1.Stop(); } } private async void timer1_Tick(object sender, EventArgs e) { await Task.Run(() => { this.Invoke(new Action(() => { label5.Text = WebSocketServer._classInfos.Count.ToString(); label6.Text =WebSocketServer.IWebSocketUserinfo.Count.ToString(); label7.Text = WebSocketServer.IWebSocketUserinfo.Where(c=>c.UserType == 1 ).ToList().Count().ToString(); label8.Text = WebSocketServer.IWebSocketUserinfo.Where(c => c.UserType == 0).ToList().Count().ToString(); })); }); } } }