node+WebSocket

const WebSocket = require("ws");
//开一个8080的端口
const WebSockets = new WebSocket.Server({ port: 8080 });
//链接
WebSockets.on("connection", function connection(socket) {
  //接收参数
  socket.on("message", function incoming(message) {
    // 收到的是buffer类型
    // console.log("收到了", message, message.toString("utf8"));
  });

  // 发送参数
  socket.send(`XXX真帅`);
});

 

posted @ 2024-04-24 09:44  QinHaoRan  阅读(13)  评论(0)    收藏  举报