Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

how to stay connected to Socket Server from the Client even on refresh on any browser #5380

Unanswered
dhavalveera asked this question in Q&A
Discussion options

Hello,

I've written Sockets.IO Server Code in Nodejs + Expressjs with TypeScript and the Server code is working perfectly fine.

but I am struggling for the Reactjs Client Side Web App, where I am not able to stay connected to the Sockets Server even on the page refresh, if I am refreshing the Page, then it's getting disconnected and then connect again, but I can't able to find a way to stay connected to the Sockets Server even on page refresh...

Furthermore, Socket Client Options I tried this as well, but this also not working in my Reactjs App.

can anyone help me on this?

You must be logged in to vote

Replies: 3 comments 2 replies

Comment options

Hi!

The WebSocket connection does not survive the page reload. If you need to track which user is connected, you will need to have some kind of authentication (a cookie, for example).

Reference: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

You must be logged in to vote
0 replies
Comment options

Hello @darrachequesne -- so I can say that, it's the normal & expected behavior of SocketsIO to get disconnect on the page reload?

You must be logged in to vote
2 replies
Comment options

Yes, that's right. As far as I know, there are no way to persist the connection across page reloads, even within a SharedWorker, which will be killed once there is no more tab connected to it.

References:

Comment options

but how Cookie or something for some kind of authentication will work? @darrachequesne

Comment options

You can utilize PWA and service workers if you really need to be connected after refresh.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /