Files
wb_InteractiveClassroomSocket/Form1.cs
2025-12-11 10:01:36 +08:00

56 lines
1.6 KiB
C#

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:8182";
_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();
}));
});
}
}
}