重构服务端为接口式(WebSocketServer(port)+addHandler 工厂,每连接独立 handler),组管理与发送收敛为链式门面 group(name)/conn(connId),统一 send 三重重载,升级版本 1.1.0

This commit is contained in:
2026-08-24 23:52:15 +08:00
parent 0a14859e8e
commit 9b79e6690d
8 changed files with 701 additions and 273 deletions
+4 -4
View File
@@ -7,7 +7,7 @@
* client.onMessage = { (m) => println(m.text) }
* client.onClose = { (code, reason) => println("关闭: ${code} ${reason}") }
* client.connect()
* client.sendText("hello")
* client.send("hello")
* client.close() // 或 client.terminate() 立即断开
*
* 说明:
@@ -117,13 +117,13 @@ public class WebSocketClient {
}
}
/// 发送文本消息。
public func sendText(text: String): Unit {
/// 发送文本消息(三重重载:WebSocketMessage / String / Array<Byte>
public func send(text: String): Unit {
frame.getOrThrow().writeText(text)
}
/// 发送二进制消息。
public func sendBinary(data: Array<Byte>): Unit {
public func send(data: Array<Byte>): Unit {
frame.getOrThrow().writeBinary(data)
}