using System.Net.WebSockets; using System.Text; using Newtonsoft.Json; namespace MauMau_Server.Websockets; public class ConnectionInstance { public Guid Id { get; set; } public string Name { get; set; } [JsonIgnore] public WebSocket Socket { get; set; } public ConnectionInstance(string name, Guid 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); } }