I am trying to get the postman api for websockets working, however I can't even make a connection:
When I try to make a connection
ws://localhost:5001/socket.io/
results in:
Error: Unexpected server response: 400 //for ws
//index.js
const port=5001
io.on("connection", (socket) => {
//handshake and hydrate and test
console.log("Client connected",socket.id);
socket.on("test", (data)=>{
console.log("test data is:",data)
socket.emit("test", "server heard you!")
});
what is the proper url string to connect to a socket.io/express/nodejs server?
I am trying to get the postman api for websockets working, however I can't even make a connection:
When I try to make a connection
ws://localhost:5001/socket.io/
results in:
Error: Unexpected server response: 400 //for ws
//index.js
const port=5001
io.on("connection", (socket) => {
//handshake and hydrate and test
console.log("Client connected",socket.id);
socket.on("test", (data)=>{
console.log("test data is:",data)
socket.emit("test", "server heard you!")
});
what is the proper url string to connect to a socket.io/express/nodejs server?
Share Improve this question asked May 24, 2021 at 18:07 altruiosaltruios 1,0832 gold badges15 silver badges32 bronze badges1 Answer
Reset to default 5Socket.io supports polling
and websocket
transports.
To connect with Postman's WebSocket client, we have to explicitly set the WebSocket transport while connecting to a Socket.io server.
This can be done by setting the transport=websocket
parameter in the connection URL.
In your case, it will be: ws://localhost:5001/socket.io/?transport=websocket
.