Answer the question
In order to leave comments, you need to log in
Console application running on websockets?
using System;
using System.Text;
using System.Threading.Tasks;
using System.Net.WebSockets;
using System.Threading;
using System.Net;
namespace ConsoleApp
{
class Program
{
static async Task SendTicksRequest()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
var ws = new ClientWebSocket();
var uri = new Uri("wss://ws.binaryws.com/websockets/v3");
await ws.ConnectAsync(uri, CancellationToken.None);
var reqAsBytes = Encoding.UTF8.GetBytes("{"ticks":"R_100"}");
var ticksRequest = new ArraySegment(reqAsBytes);
await ws.SendAsync(ticksRequest,
WebSocketMessageType.Text,
true,
CancellationToken.None);
var buffer = new ArraySegment(new byte[1024]);
var result = await ws.ReceiveAsync(buffer, CancellationToken.None);
string response = Encoding.UTF8.GetString(buffer.Array, 0, result.Count);
Console WriteLine(response);
}
static void Main(string[] args)
{
SendTicksRequest();
Console.ReadLine();
}
}
}
when I try to compile it, I get an error
The element "WebSocketMessageType" does not exist in the current context.
The type name or namespace "ClientWebSocket" could not be found (using directive or assembly reference missing?)
I understand that I need to add the .Net library, but how do I do it? I have Visual Studio 2013
Answer the question
In order to leave comments, you need to log in
Open SolutionExplorer. Look for the "References" folder. On it, right-click and click Add Reference. Inside, select "Assemblies" -> Framework and look for the assembly you need in the list.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question