WebSocketSharp 的使用
程序员文章站
2023-10-27 21:01:40
Server 端示例代码: Client 端示例代码: It supports: WebSocket Client and Server RFC 6455 Per message Compression extension Secure Connection HTTP Authentication ......
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); } } }
- it supports:
- websocket client and server
- rfc 6455
- per-message compression extension
- secure connection
- http authentication
- query string, origin header and cookies
- infinite streaming
- .net 4.5 or later
install-package websocketsharp -version 1.0.3-rc11
上一篇: 秋季孩子容易犯鼻炎 四个方法护理宝宝鼻子
下一篇: TP5 使用验证码功能