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!");
});
});
此处,该消息显示在localhost下的dev tools网络面板上。但是,在节点终端中,它显示为客户端已向我们发送:$ {data},而预期的结果是客户端已向我们发送了:无论客户端发送的消息是什么。 我将随附终端的屏幕截图。预先感谢。Image of the terminal