refactor and chat base
This commit is contained in:
22
Websockets/WebsocketManager.cs
Normal file
22
Websockets/WebsocketManager.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user