refactor and chat base

This commit is contained in:
2023-04-22 12:42:02 +02:00
parent 2c7e7303bc
commit e4769d4b99
11 changed files with 231 additions and 144 deletions

View File

@@ -0,0 +1,22 @@
using System.Net.WebSockets;
using System.Text;
namespace MauMau_Server.Websockets;
public static class WebsocketManager
{
public static void SendAsync(WebSocket socket, string message)
{
var bytes = Encoding.Default.GetBytes(message);
var arraySegment = new ArraySegment<byte>(bytes);
socket.SendAsync(arraySegment, WebSocketMessageType.Text, true, CancellationToken.None);
}
public static void BroadcastAsync(List<WebSocket> sockets, string message)
{
foreach (var socket in sockets)
{
SendAsync(socket, message);
}
}
}