Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System;
using System.Threading;
using WebSocketSharp;
namespace TestWebSocketSharp
{
class Program
{
private enum SslProtocolsHack
{
Tls = 192,
Tls11 = 768,
Tls12 = 3072
}
static void Main(string[] args)
{
using (var ws = new WebSocket("wss://stream-testnet.bybit.com/realtime"))
{
Console.WriteLine("ReadyState = " + ws.ReadyState.ToString()); // ReadyState=Connecting 상태
ws.OnOpen += (sender, e) =>
{
Console.WriteLine("OnOpen");
Console.WriteLine("ReadyState = " + ws.ReadyState.ToString()); // ws.Connect 가 성공적이면 ReadyState 는 Open 이며 이 상태에서 서버와 통신가능.
};
ws.OnClose += (sender, e) =>
{
Console.WriteLine("OnClose");
var sslProtocolHack = (System.Security.Authentication.SslProtocols)(SslProtocolsHack.Tls12 | SslProtocolsHack.Tls11 | SslProtocolsHack.Tls);
//TLS 핸드세이크 오류 발생시 프로토콜 변경하여 재접속처리함.
if (e.Code == 1015 && ws.SslConfiguration.EnabledSslProtocols != sslProtocolHack)
{
ws.SslConfiguration.EnabledSslProtocols = sslProtocolHack;
ws.Connect();
}
};
ws.OnMessage += (sender, e) =>
{
Console.WriteLine("OnMessage : " + e.Data);
};
ws.Connect(); // Connect to the server.
Console.WriteLine("\nType 'exit' to exit.\n");
while (true)
{
Thread.Sleep(100);
Console.Write("> ");
var msg = Console.ReadLine();
if (msg == "exit")
break;
}
} // using (var ws = new WebSocket("wss://stream-testnet.bybit.com/realtime"))
} // static void Main(string[] args)
} // class Program
}
@igotit-anything
Copy link
Author

igotit-anything commented Dec 26, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment