websocket

command
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

README

websocket —— WebSocket 示例

演示 pkg/transport/ws 的 Echo 连接与 JSON 广播两种常见模式,配合 pkg/messaging/stream 做 fan-out。

运行

go run ./examples/websocket
# Echo:发什么回什么
websocat ws://localhost:8080/echo

# 广播:每 2 秒收到一条 JSON 通知
websocat ws://localhost:8080/notice

说明

  • /echows.Handler 读一条写一条,适合调试连通性。
  • /noticews.BroadcastJSON(hub)stream.Broadcaster[notice] 推给所有订阅连接;后台 goroutine 定时 Publish
  • 慢客户端缓冲区满时丢帧,不阻塞广播源(stream.WithBufferSize 可调)。

Documentation

Overview

WebSocket 示例:echo 端点 + JSON 广播端点。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL