Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
binary
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Text; using System.Threading.Tasks; using System.Net.WebSockets; using System.Threading; using System.Net; namespace Rextester { public class Program { private ClientWebSocket ws = new ClientWebSocket(); private Uri uri = new Uri("wss://ws.binaryws.com/websockets/v3"); public async Task SendRequest(string data) { while(this.ws.State == WebSocketState.Connecting){}; if (this.ws.State != WebSocketState.Open) { throw new Exception("Connection is not open."); } var reqAsBytes = Encoding.UTF8.GetBytes(data); var ticksRequest = new ArraySegment<byte>(reqAsBytes); await this.ws.SendAsync(ticksRequest, WebSocketMessageType.Text, true, CancellationToken.None); Console.WriteLine("The request has been sent: "); Console.WriteLine(data); Console.WriteLine("\r\n \r\n"); } public async Task StartListen(){ WebSocketReceiveResult result; while (this.ws.State == WebSocketState.Open){ var buffer = new ArraySegment<byte>(new byte[1024]); do { result = await this.ws.ReceiveAsync(new ArraySegment<byte>(buffer.Array), CancellationToken.None); if (result.MessageType == WebSocketMessageType.Close) { Console.WriteLine("Connection Closed!"); break; } else { var str = Encoding.UTF8.GetString(buffer.Array, 0, result.Count); Console.WriteLine("Received Data at: " + DateTime.Now); Console.WriteLine(str); Console.WriteLine("\r\n"); } } while (!result.EndOfMessage); } } public async Task Connect(){ Console.WriteLine("Prepare to connect to: " + this.uri.ToString()); Console.WriteLine("\r\n"); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; await ws.ConnectAsync(uri, CancellationToken.None); Console.WriteLine("The connection is established!"); Console.WriteLine("\r\n"); } public static void Main(string[] args) { string data = "{\"ticks\":\"R_100\"}"; var bws = new Program(); bws.Connect().Wait(); bws.SendRequest(data).Wait(); bws.StartListen(); Console.ReadLine(); } } }
run
|
edit
|
history
|
help
0
first case
Trim Strings
Contravariance
dynamic in C#
Compression Decompressor
kod 1
Exemple Regex
Greatest Common Divisor of 2 or more numbers.
my sql
1.2 Basics: object orientation