mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-04-15 05:27:16 +00:00
feat: implement WebSocket classes and update culture settings; bump PepperDashCore version
This commit is contained in:
parent
8be5481ac9
commit
bdd398e2e6
8 changed files with 185 additions and 8 deletions
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class SomeOtherWebSocketClass
|
||||
{
|
||||
private ClientWebSocket _webSocket;
|
||||
|
||||
public SomeOtherWebSocketClass()
|
||||
{
|
||||
_webSocket = new ClientWebSocket();
|
||||
}
|
||||
|
||||
public async Task ConnectAsync(Uri uri)
|
||||
{
|
||||
await _webSocket.ConnectAsync(uri, CancellationToken.None);
|
||||
}
|
||||
|
||||
public async Task SendAsync(string message)
|
||||
{
|
||||
var buffer = System.Text.Encoding.UTF8.GetBytes(message);
|
||||
await _webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Text, true, CancellationToken.None);
|
||||
}
|
||||
|
||||
public async Task<string> ReceiveAsync()
|
||||
{
|
||||
var buffer = new byte[1024];
|
||||
var result = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
|
||||
return System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count);
|
||||
}
|
||||
|
||||
public async Task CloseAsync()
|
||||
{
|
||||
await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, string.Empty, CancellationToken.None);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue