标签:cat ram void var prot oid ini already main
Server 端示例代码:
class Program
{
static void Main(string[] args)
{
var wssv = new WebSocketServer("ws://localhost:8080");
wssv.AddWebSocketService<Laputa>("/Laputa");
wssv.Start();
Console.ReadKey(true);
wssv.Stop();
}
}
public class Laputa : WebSocketBehavior
{
protected override void OnMessage(MessageEventArgs e)
{
var msg = e.Data == "BALUS"
? "I've been balused already..."
: "I'm not available now.";
Send(msg);
}
}
Client 端示例代码:
class Program
{
static void Main(string[] args)
{
using (var ws = new WebSocket("ws://localhost:8080/Laputa"))
{
ws.OnMessage += (sender, e) =>
Console.WriteLine("Laputa says: " + e.Data);
ws.Connect();
ws.Send("BALUS");
Console.ReadKey(true);
}
}
}
Install-Package WebSocketSharp -Version 1.0.3-rc11
标签:cat ram void var prot oid ini already main
原文地址:https://www.cnblogs.com/hippieZhou/p/9898322.html