I implemented chat on web sockets according to this article https://habrahabr.ru/post/145077/ I added it to Azure and discovered a problem - when I open a new page with chat, I sometimes get a new static variable Clients and then this chat is no longer sending Messages to previously opened pages, although they work fine among themselves. It turns out that different chats can have different static variables Clients with their lists of web sockets.

 // Список всех клиентов private static readonly List<WebSocket> Clients = new List<WebSocket>(); 

Please tell me how you can solve this problem? Can you configure that a new static variable is not created? Or can you keep a list of Clients elsewhere?

    1 answer 1

    As soon as several instances of your application are launched behind the balancer, then it is necessary to realize the communication of these instances among themselves. Each of them naturally works in isolation and gets its static variable Clients. It is necessary to organize the transfer of messages between instances of the application.

    Look towards SignalR and how to implement scaling SignalR Scaleout

    Communication between Azure Web Sites can only be organized via the Azure Service bus. Or another queue. Or exchange messages through the database. For Azure Web Roles, the ability to interact between roles in a virtual network is added.

    • Or look towards Interrole Communication if your application is spinning on Azure Web Roles ... - Walter Nuss
    • one
      In fact, there is no difference in how to implement; the most important thing for horizontal scaling is to know that messages need to be routed between application instances. - Eugene
    • This is the main question - what are the ways to route messages between application instances. And which is the easiest for Azure Web Sites. And the principle of their work is also interesting - only internal endpoints or are there other options? - Vitaliy
    • I added in response, be sure to look about SignalR Scaleout, there the whole principle is depicted by the very first picture. - Eugene
    • Thank you all, very useful information, but the solution was much easier! manage.windowsazure.com - for some reason, there were 2 copies in the scaling section. Put 1 and it all worked. - Vitaliy