Testing 邮递员websocket api,”;“已连接”但没有来自服务器的消息或确认

Testing 邮递员websocket api,”;“已连接”但没有来自服务器的消息或确认,testing,websocket,socket.io,postman,Testing,Websocket,Socket.io,Postman,我无法让postman使用WebSocket连接到服务器 const port =5001; io.on("connection", (socket) => { console.log("Client connected",socket.id); socket.emit("handshake","connected to backend"); socket.on("test",

我无法让postman使用WebSocket连接到服务器

const port =5001;
io.on("connection", (socket) => {
  console.log("Client connected",socket.id);
  socket.emit("handshake","connected to backend");
  socket.on("test", (data)=>{
    console.log("test data is:",data);
    socket.emit("test", "server heard you!")
  });
}
在邮递员中,请求地址为:

ws://localhost:5001/socket.io/?transport=websocket
症状是:邮递员说它是连通的。但如果我尝试发送任何东西,它会在超时后断开连接。 如果我将重新连接尝试设置为1,它将在断开连接时自动重新连接

但我不认为它实际上是在连接——因为服务器上没有发生任何事情(没有新的客户端连接消息)

我也尝试过邮件的格式,但没有效果

42["test","i hear you"]
42[test,i hear you]
["test":"i hear you"]
{"test":"I hear you"}
42{"test":"I hear you"}
{"event":"test","data":"I hear you"}
42{"event":"test","data":"I hear you"}
42["event","test","data","I hear you"]
["event","test","data","I hear you"]

我已经检查了控制台的结果,还没有找到线索。我可能遗漏了什么?

您将socket.io用作WebSocket,但这不起作用,因为socket.io不是WebSocket的实现

从官方socket.io文档:

Socket.IO不是WebSocket实现。虽然Socket.IO确实在可能的情况下使用WebSocket作为传输,但它会向每个数据包添加额外的元数据。这就是为什么WebSocket客户端无法成功连接到Socket.IO服务器,而Socket.IO客户端也无法连接到普通WebSocket服务器


来源:

这是不正确的。socket.io现在在8.5版本就得到了支持,请在github上与开发人员交谈确认这一点。然而,他们仍在编写文档。
// WARNING: the client will NOT be able to connect!
const socket = io("ws://echo.websocket.org");