Skip to content

Instantly share code, notes, and snippets.

@igotit-anything
Last active December 26, 2020 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igotit-anything/fd4c7f460023aca793bd3d8694453aeb to your computer and use it in GitHub Desktop.
Save igotit-anything/fd4c7f460023aca793bd3d8694453aeb to your computer and use it in GitHub Desktop.
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"))
}
}
}
@igotit-anything
Copy link
Author

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