问题
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?
回答1:
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
回答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.
回答3:
You could implement a locking mechanism which allows only one connection per multiple tabs.
- store the value of this lock in local storage
- 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).
- 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.
- 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.
回答4:
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.
来源:https://stackoverflow.com/questions/25668095/waiting-for-available-sockets-in-asp-net-using-signalr