Answer the question
In order to leave comments, you need to log in
C#, why doesn't it hook a WebSocket connection?
Good!
There is a js client that accepts WebSocket connections:
var socket = new WebSocket("ws://127.0.0.1:8005");
// ... и так далее, обработка сообщений
namespace SocketTcpServer
{
class Program
{
public static async Task SendTicksRequest()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
var ws = new ClientWebSocket();
var uri = new Uri("ws:127.0.0.1:8005");
await ws.ConnectAsync(uri, CancellationToken.None);
var reqAsBytes = Encoding.GetEncoding(1251).GetBytes("{\"ticks\":\"R_100\"}");
Console.WriteLine(reqAsBytes);
var ticksRequest = new ArraySegment<byte>(reqAsBytes);
await ws.SendAsync(ticksRequest,
WebSocketMessageType.Text,
true,
CancellationToken.None);
var buffer = new ArraySegment<byte>(new byte[1024]);
var result = await ws.ReceiveAsync(buffer, CancellationToken.None);
string response = Encoding.GetEncoding(1251).GetString(buffer.Array, 0, result.Count);
Console.WriteLine(response);
}
static void Main(string[] args)
{
SendTicksRequest();
Console.ReadLine();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question