using System.Net.WebSockets; using System.Text; namespace MauMau_Server.Websockets; public class ConnectionInstance { public string Name { get; set; } public string Id { get; set; } public WebSocket Socket { get; set; } public ConnectionInstance(string name, string id, WebSocket socket) { Name = name; Id = id; Socket = socket; } /** * * Sends a message to the client. This method is asynchronous and formats the message to be ready to be sent. * */ public void SendMessageAsync(string message) { var bytes = Encoding.Default.GetBytes(message); var arraySegment = new ArraySegment(bytes); Socket.SendAsync(arraySegment, WebSocketMessageType.Text, true, CancellationToken.None); } }