Last active
December 26, 2020 14:00
-
-
Save igotit-anything/b9e9971ac654d619e7138c4baf510ae4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://igotit.tistory.com/2739