hi @繁伸 松尾 have you solved your issue? I'm in a similar situation (standalone, no Azure) with same results as you...
Can not connect to socket.io with websocket
繁伸 松尾
51
Reputation points
Hi,
This is my Azure NodeJS AppService's socket.io setup
Client side:
const socket = io('https://testappsocket.azurewebsites.net', {
withCredentials: true,
forceNew: true,
reconnectionAttempts: "Infinity", //avoid having user reconnect manually in order to prevent dead clients after a server restart
timeout: 10000, //before connect_error and connect_timeout are emitted.
transports: ['websocket']
});
socket.on("notify", (msg) => {
console.log("getting socket msg");
console.log(msg.message);
this.get_socket_message = msg.message;
});
Server side:
var io = require('socket.io')(server, {
cors: {
origin: "https://testappsocket.azurewebsites.net",
methods: ["GET", "POST"],
credentials: true,
},
transports: ['websocket']
});
console.log("getSocekt.js : ")
console.log(msg)
var rtnMessage = { message: msg };
io.emit('notify', rtnMessage);
But my client can not receive message from server or occasionally it can only receive first message, from the second onwards the "WebSocket is closed before closed before the connection is established" error message always shown.
I am using Socket.io version 3.1.0 with NodeJS 14.15.1
How can I fix this ? Thank you very much