different connection in Browser multiple tabs

杀马特。学长 韩版系。学妹 提交于 2019-12-23 10:25:22

问题


Why SignalR is making different connection in browser multiple tabs for same logged-in user. Is there any way to make one connection for all tabs opened in same browser. From connection I mean connectionID of a user in SignalR.


回答1:


Because different tabs of the same browser are different documents\"processes" - each tab in some sense represents different "instance" of client app. There is no way to share JavaScript objects between them directly (and thats the reason why SignalR opens new connection in each tab). To share data\communicate between different instances, you can use for example HTML5 localStorage mechanism

So if you want to share one SignalR connection between tabs, the way to go is to implement it yourself by managing connection only in one tab and allowing communication between tabs so that every tab has the ability to send\receive messages from server. You can use or get inspired by this cool project which does exactly that.

This also solves the problem of browser limit of maximum concurrent connections to single server.



来源:https://stackoverflow.com/questions/30587888/different-connection-in-browser-multiple-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!