question

92705102 avatar image
0 Votes"
92705102 asked ·

Can not connect to socket.io with websocket

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





azure-webappsazure-webapps-content-deploymentazure-webapps-apis
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@92705102 Thank you for your question. We apologize for the delay in getting back to you.

What tier of web apps are you using? For example, the free tier only allows for 5 websockets per instance. I see that your code allows for unlimited retries, and I wonder if you're hitting this limit. The standard tier has unlimited connections. Would you be willing to temporarily scale up to an S1 instance and try your test again? Please note that running higher tiers will generate additional tiers but you can scale back down after completing your tests.

For more information on these limits, please see here.


0 Votes 0 ·
92705102 avatar image 92705102 brtrachMSFT-0711 ·

I am using B2 plan. But I have to disconnect and reconnect every time send request to server to receive notification.

0 Votes 0 ·

0 Answers