Rename folder from Shogi.Sockets to Shogi.Api

This commit is contained in:
2022-11-09 09:11:25 -06:00
parent 3257b420e9
commit a1f996e508
41 changed files with 6 additions and 6 deletions

View File

@@ -0,0 +1,21 @@
using System.Net.WebSockets;
using System.Text;
namespace Shogi.Api.Extensions
{
public static class WebSocketExtensions
{
public static async Task SendTextAsync(this WebSocket self, string message)
{
await self.SendAsync(Encoding.UTF8.GetBytes(message), WebSocketMessageType.Text, true, CancellationToken.None);
}
public static async Task<string> ReceiveTextAsync(this WebSocket self)
{
var buffer = new ArraySegment<byte>(new byte[2048]);
var receive = await self.ReceiveAsync(buffer, CancellationToken.None);
return Encoding.UTF8.GetString(buffer.Slice(0, receive.Count));
// TODO: Make this robust to multi-frame messages.
}
}
}