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.
The Broadcast Channel API allows communication between Tabs, Windows, Frames, Iframes, and Web Workers. One Tab can create and post to a channel as follows. const channel = new BroadcastChannel('app-data'); channel.
If you use many tabs to connect to the same remote server (or there are many users connecting to the server) they all go to the same port and are serviced by the same process (i.e. the web server of the site). This is the correct answer. TCP connections have a port number on both ends.
Each connection to a website uses a different socket with default destination TCP port 80 for plain HTTP and 443 for HTTPS.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With