如何使用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!");
  });
});

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

hzcker 回答:如何使用node.js和Web套接字在终端上显示客户端数据

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1367208.html

大家都在问