Last active
December 26, 2020 15:32
-
-
Save igotit-anything/fd4c7f460023aca793bd3d8694453aeb 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 | |
{ | |
static void Main(string[] args) | |
{ | |
// test WebSocketSharp | |
using (var ws = new WebSocket("ws://echo.websocket.org")) | |
{ | |
Console.WriteLine("ReadyState = " + ws.ReadyState.ToString()); // ReadyState=Connecting 상태 | |
ws.OnOpen += (sender, e) => //ws.Send("Hi, there!"); | |
{ | |
Console.WriteLine("OnOpen" ); | |
Console.WriteLine("ReadyState = " + ws.ReadyState.ToString()); // ws.Connect 가 성공적이면 ReadyState 는 Open 이며 이 상태에서 서버와 통신가능. | |
}; | |
ws.OnClose += (sender, e) => | |
{ | |
Console.WriteLine("OnClose"); | |
}; | |
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(1000); | |
Console.Write("> "); | |
var msg = Console.ReadLine(); | |
if (msg == "exit") | |
break; | |
// Send a text message. | |
ws.Send(msg); | |
} | |
} // using (var ws = new WebSocket("ws://echo.websocket.org")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://igotit.tistory.com/2739