17

I am using SignalR to implement the Chat in asp.net but when I open multiple tabs of my web application I am getting "Waiting for Available Sockets...".

I have implemented all settings specified on Performance Tuning SignalR but my problem is not getting solved from this.

How can I resolve this issue?

usr
  • 168,620
  • 35
  • 240
  • 369
G.S Bhangal
  • 3,060
  • 4
  • 23
  • 48
  • 1
    Are you just trying to get the basic demo running? Or are you actually trying to performance tune a real application? – mason Sep 04 '14 at 14:30
  • Where did you get the code for this chat application or did you write it from scratch yourself? – Sven Grosen Sep 04 '14 at 14:32
  • i write it from scratch and when i open more than 5 tabs the tabs are loading .... unless i close the previos tabs – G.S Bhangal Sep 04 '14 at 14:33
  • 1
    Browsers have limits about how many concurrent connections can be open which you are probably hitting. Take a look at this: http://stackoverflow.com/questions/985431/max-parallel-http-connections-in-a-browser – Pawel Sep 04 '14 at 21:04
  • @Pawel that means i an able to open tabs more than 6 in firefox ? I really need to open minumum 10 tabs ... – G.S Bhangal Sep 05 '14 at 05:46
  • @G.SBhangal - You can open 10 tabs but the default numer of concurrent connections is typically less than 10. Since SignalR opens a connection and keeps it active once you reach the limit any new tab using SignalR won't work. – Pawel Sep 05 '14 at 06:29
  • @Pawel I am using the signal R on master page..... So it will work of every page..... Can you provide me any solution how can i do this... – G.S Bhangal Sep 05 '14 at 09:04
  • When you say 10 tabs is it 10 users or 10 conversations for the same user? if it is 10 users just open different browser instances. if it is the same user your only option is to have just one channel and manage the different conversations on the same tab maybe by simulating tabs yourself? – Pedro.The.Kid Sep 10 '14 at 10:11
  • @Pedro.The.Kid a user has a different tabs open and each tab need a connection to send chat messages... How can i simulate the tabs ,any idea? – G.S Bhangal Sep 11 '14 at 05:00
  • It is not good to have 10 connections open for each user just 100 users will create 1000 connections, this is not a good practice.Create a single page app and make all the conversations on the same connection. and for each conversation have a buttons with a div for the conversation. – Pedro.The.Kid Sep 11 '14 at 09:09
  • @Pedro.The.Kid I am working with the master page and my chat popup is on the right side of every page like Facebook. Because chat user list and chat message box is visible on every page – G.S Bhangal Sep 11 '14 at 10:18
  • What OS are you using? It sounds like you get longpolling as the transport since websockets does not have a limit to 6 connections. – Uffe Sep 15 '14 at 12:59
  • @Uffe i am using Windows Server 2008 R2 Standard on production and Windows 8.1 Pro on my local machine – G.S Bhangal Sep 15 '14 at 13:32
  • Ok, So you will be able to get websockets on your local machine but never on the production machine. Have you enabled websockets in the IIS on your local machine? If running IIS express I think there will be a limit on 10 connections even if you have websockets. But as I said, it sounds like you have another trasnport then websockets... And you might as well have it that way since SignalR does not support websockets on 2008 server. – Uffe Sep 15 '14 at 13:58

4 Answers4

9

As already indicated in the comments, you're hitting the connection limit per hostname which is enforced by the browser.

Your basic options are

  • single page app that has tabs in its UI so the user doesn't have to use browser tabs
  • sharing the connection in some way, e.g. as discussed in this question
  • separate subdomains
Community
  • 1
  • 1
Lars Höppner
  • 18,252
  • 2
  • 45
  • 73
  • Hoppner how can I implement the separate sub domain concept.Should i have to deploy my hub class on all the domains? or is there any way? Because i have cretae 5 subdomains and i pass the connection as $.connection.hub.url = 'subdomain url'; – G.S Bhangal Sep 11 '14 at 04:58
  • you could deploy it for each location and connect the instances with a backplane; or maybe it's possible to simply use url rewriting / custom routing (I've never tried so there might be complications) – Lars Höppner Sep 11 '14 at 09:00
  • can you please provide me some idea of example of implemenation using url rewriting because i have tried deploying on multiple server but my chat messages are not working.. due to the connection ID not common for multiple hubs – G.S Bhangal Sep 11 '14 at 10:21
  • the connection id will be different for each tab in any case (even if it's on the same server), unless you share the connection between tabs; you could use groups to address multiple connections belonging to the same user; if you have multiple instances, you'll need the backplane to forward messages between the different nodes – Lars Höppner Sep 11 '14 at 10:54
  • i used the Separate sub domains concept because i need the chat window on every page like on facebook, So i can not use the UI tabs for this. – G.S Bhangal Nov 05 '14 at 05:14
2

You could implement a locking mechanism which allows only one connection per multiple tabs.

  1. store the value of this lock in local storage
  2. set it to true before you open new connection, release it (set to false) before you close the connection (you may need to react on window.beforeunload event).
  3. create a timer which periodically checks the value of this lock. (You need to do this because the user could close the tab where the active connection lives) Opens new connection only when the value of this lock is false.
  4. broadcast the received message from the active tab to others (passive tabs). Store the message value in local storage while the other tabs periodically checks this for a new values. The passive tabs should store the timestamp of the last revived message and look only for a messages newer then this timestamp.

This solution will help you to handle the max parallel connections limit.

Marian Ban
  • 8,158
  • 1
  • 32
  • 45
2

Solution with the local storage is implemented in this small project:

https://github.com/slimjack/IWC-SignalR

I tried it in my application and can strongly recommend as it worked for me. I tested it on chrome, firefox and IE and was happy with performance.

Remember that you should include iwc-all.min.js, iwc-signalr.js and signalr-patch.js before a reference <script src="signalr/hubs"></script>.

It is ready to work good with jQuery 1.7 or higher. With small changes I was able to run it with version 1.6.4.

Marta
  • 326
  • 4
  • 11
0

After struggling with this issue i have resolved this by using the sub-domain concept. For this i have created multiple sub-domains pointing to the Main site and each time i specify the hub url from different domain so i was able to open about 5 tabs from each domain. And this trick is working fine for me.

G.S Bhangal
  • 3,060
  • 4
  • 23
  • 48