Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

different connection in Browser multiple tabs

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.

like image 502
Amna Avatar asked Jun 02 '15 05:06

Amna


People also ask

How do different tabs of a browser communicate?

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.

What happens if two browser tabs go to the same Web server?

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.

Does each browser tab have its own port?

Each connection to a website uses a different socket with default destination TCP port 80 for plain HTTP and 443 for HTTPS.


1 Answers

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.

like image 159
Michal Levý Avatar answered Sep 16 '22 15:09

Michal Levý