initial commit
This commit is contained in:
27
client/test-client.js
Normal file
27
client/test-client.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import WebSocket from "ws";
|
||||
|
||||
const ws = new WebSocket("ws://localhost:8080");
|
||||
|
||||
ws.on("open", () => {
|
||||
console.log("✅ 已连接 WebSocket");
|
||||
|
||||
ws.send(JSON.stringify({ type: "auth", app: "demo" }));
|
||||
|
||||
ws.send(JSON.stringify({ type: "subscribe", channel: "chat" }));
|
||||
|
||||
setTimeout(() => {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
type: "publish",
|
||||
app: "demo",
|
||||
channel: "chat",
|
||||
event: "message",
|
||||
data: { text: "Hello Redis WS 🚀" },
|
||||
})
|
||||
);
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
ws.on("message", (msg) => {
|
||||
console.log("📩 收到消息:", msg.toString());
|
||||
});
|
||||
Reference in New Issue
Block a user