Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  19] [ 2]  / answers: 1 / hits: 9094  / 10 Years ago, thu, march 27, 2014, 12:00:00

I have a web application where a persistent connection from the server to it's clients (browser) is needed in order push news / updates to the clients in (near) real-time. This would not be so tricky if the navigation through some elements of the website would not cause complete page refreshs.



Polling (standard way or long polling) the server for news is not an option, since it results in often unnecessary request calls (because no news are available). Moreover news can rise up randomly. Therefore with the polling strategy the server would go down...
For the websocket (bidirectional communication channel) the client and server have to accept the upgrade to websocket.
A similar problem was discussed here, but no satisfying solution was found.



Data can survive a full page refresh by storing it in cookies or other ways:




  • cookies

  • window.name (www.thomasfrank.se/sessionvars.html)

  • localstorage: stores the data with no expiration date. The data will not be deleted
    when the browser is closed. Example: Perseverance (github.com/viseztrance/perseverance)

  • PersistJS: Cross Browser Client-Side Persistent Storage without cookies Storing the
    Javascript object is done, by serialize / deserialize the object.



Is there something that works similar for „running“ objects like websockets?



Some possibilities I thought of, are:




  • An old style „solution“ would be to put the whole web application in an iFrame and add the connection to the outermost window (of the frame). This is not an option since it causes a lot of different other problems.

  • Since HTML5 Share Web Workers exits, but because of the limited browser support this can also not be used.



So my question is: Is there a possibility / hack how I can keep my websocket connection open also if the page is refreshed? So that I don't have to reinitialize the connection to the server?


More From » html

 Answers
2

Simple answer - best solution is to change your server part, so it can handle connection lost and recovery (And use cookies to keep session id or something else).



As I cannot see any requirement to achive this literally. And even more - you can loose connection not because of referesh but because of connection problems (But you can figure out which of them happened)


[#46493] Wednesday, March 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kyla

Total Points: 77
Total Questions: 108
Total Answers: 111

Location: Grenada
Member since Mon, May 8, 2023
1 Year ago
;