node.js - 如何使用 node.js 和 web 套接字在终端上显示客户端的数据
问题描述
const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8082 });
wss.on("connection", (ws) => {
console.log("New client connected!");
ws.on("message", (data) => {
console.log("Client has sent us: ${data}");
});
//ws.send(data.toUpperCase());
ws.on("close", () => {
console.log("Client has disconnected!");
});
});
在这里,消息显示在本地主机下的开发工具网络面板上。但是,在节点终端中,它显示为 Client has sent us: ${data} 而预期的结果是 Client 已经向我们发送了:无论客户端发送的消息。我将附上终端的屏幕截图。提前致谢。终端图片
解决方案
推荐阅读
- cmake - 无法链接到子弹物理库 - LNK2019、LNK2001
- javascript - 为什么 Javascript 中没有 HTMLSectionElement 和 HTMLArticleElement?
- sas - SAS:打印与最小值相关的名称
- flutter - 错误:无法解析“package:flutter_localizations/flutter_localizations.dart”中的“flutter_localizations”包
- jq - jq 使用 --arg 返回“无效的数字文字”
- c# - 如何解决 Lambda 函数中 ai_flags 的错误值错误
- swiftui - SwiftUI:“某些视图”类型的值没有成员“演示文稿”
- ubuntu - 在 Ubuntu 18 上持久化 arptables
- javascript - React Js 渲染是功能不起作用
- python - 未处理异常的错误回溯消息在哪里写入 - sys.stdout 或 sys.stderr 或其他地方?(在 Python 中)