Files
MauMau-Server/Websockets/ConnectionInstance.cs
DTieman 681cfa13bd
Some checks failed
Build Mau & Deploy Mau / build (push) Failing after 1m2s
Build Mau & Deploy Mau / deploy (push) Has been skipped
Dotnet version upgrade
2024-07-13 00:01:43 +02:00

26 lines
794 B
C#

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