26 lines
794 B
C#
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);
|
|
}
|
|
} |