Socket.io multiple pages









up vote
-3
down vote

favorite












I'm trying to create a chat using socket.io, I'm having a problem.



I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?



Thank you










share|improve this question



















  • 2




    can you post a minimal example of your code?
    – mihai
    Nov 9 at 16:32










  • do socket io from a worker. worker has state. multiple pages can msg back n forth to worker .
    – Robert Rowntree
    Nov 9 at 20:47














up vote
-3
down vote

favorite












I'm trying to create a chat using socket.io, I'm having a problem.



I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?



Thank you










share|improve this question



















  • 2




    can you post a minimal example of your code?
    – mihai
    Nov 9 at 16:32










  • do socket io from a worker. worker has state. multiple pages can msg back n forth to worker .
    – Robert Rowntree
    Nov 9 at 20:47












up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











I'm trying to create a chat using socket.io, I'm having a problem.



I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?



Thank you










share|improve this question















I'm trying to create a chat using socket.io, I'm having a problem.



I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?



Thank you







node.js socket.io chat






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 12:53









mihai

22.2k63968




22.2k63968










asked Nov 9 at 6:21









Sébastien Z'zLebrun

11




11







  • 2




    can you post a minimal example of your code?
    – mihai
    Nov 9 at 16:32










  • do socket io from a worker. worker has state. multiple pages can msg back n forth to worker .
    – Robert Rowntree
    Nov 9 at 20:47












  • 2




    can you post a minimal example of your code?
    – mihai
    Nov 9 at 16:32










  • do socket io from a worker. worker has state. multiple pages can msg back n forth to worker .
    – Robert Rowntree
    Nov 9 at 20:47







2




2




can you post a minimal example of your code?
– mihai
Nov 9 at 16:32




can you post a minimal example of your code?
– mihai
Nov 9 at 16:32












do socket io from a worker. worker has state. multiple pages can msg back n forth to worker .
– Robert Rowntree
Nov 9 at 20:47




do socket io from a worker. worker has state. multiple pages can msg back n forth to worker .
– Robert Rowntree
Nov 9 at 20:47












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










A given socket.io connection belongs only to one particular page. When the user browses to a new page (assuming you're not dynamically loading new content into the same master page using a single-page-app (SPA) architecture), that socket.io connection is closed and the new page can then open a new socket.io connection (that will have a different socket.id).




I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?




No, not when the browser is actually loading a whole new page into the current window/tab.




The usual way to create some sort of ID that is persistent when you go from one page to the next is to put an ID in a cookie and then that cookie will be available on each new page the user browses to and will stay consistent from one page to the next.



If you are using express on the server, you can use express-session to automatically create a persistent session for each new user and you can even store data in that session object that will be available on each page the user requests.






share|improve this answer






















  • @James - I do plenty of cajoling and teaching of new users on the ways of stack overflow. Plenty. I understand that need. But, even when a question is not that well written I can sometimes only find one likely meaning so I attempt to help. There is no comment at all on the OP's question asking to clarify about SPA.
    – jfriend00
    Nov 9 at 21:19










  • there was one asking the OP to provide a MVP which I upvoted, would be enough to guage whether it was an SPA or not.
    – James
    Nov 9 at 21:45











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220778%2fsocket-io-multiple-pages%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










A given socket.io connection belongs only to one particular page. When the user browses to a new page (assuming you're not dynamically loading new content into the same master page using a single-page-app (SPA) architecture), that socket.io connection is closed and the new page can then open a new socket.io connection (that will have a different socket.id).




I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?




No, not when the browser is actually loading a whole new page into the current window/tab.




The usual way to create some sort of ID that is persistent when you go from one page to the next is to put an ID in a cookie and then that cookie will be available on each new page the user browses to and will stay consistent from one page to the next.



If you are using express on the server, you can use express-session to automatically create a persistent session for each new user and you can even store data in that session object that will be available on each page the user requests.






share|improve this answer






















  • @James - I do plenty of cajoling and teaching of new users on the ways of stack overflow. Plenty. I understand that need. But, even when a question is not that well written I can sometimes only find one likely meaning so I attempt to help. There is no comment at all on the OP's question asking to clarify about SPA.
    – jfriend00
    Nov 9 at 21:19










  • there was one asking the OP to provide a MVP which I upvoted, would be enough to guage whether it was an SPA or not.
    – James
    Nov 9 at 21:45















up vote
0
down vote



accepted










A given socket.io connection belongs only to one particular page. When the user browses to a new page (assuming you're not dynamically loading new content into the same master page using a single-page-app (SPA) architecture), that socket.io connection is closed and the new page can then open a new socket.io connection (that will have a different socket.id).




I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?




No, not when the browser is actually loading a whole new page into the current window/tab.




The usual way to create some sort of ID that is persistent when you go from one page to the next is to put an ID in a cookie and then that cookie will be available on each new page the user browses to and will stay consistent from one page to the next.



If you are using express on the server, you can use express-session to automatically create a persistent session for each new user and you can even store data in that session object that will be available on each page the user requests.






share|improve this answer






















  • @James - I do plenty of cajoling and teaching of new users on the ways of stack overflow. Plenty. I understand that need. But, even when a question is not that well written I can sometimes only find one likely meaning so I attempt to help. There is no comment at all on the OP's question asking to clarify about SPA.
    – jfriend00
    Nov 9 at 21:19










  • there was one asking the OP to provide a MVP which I upvoted, would be enough to guage whether it was an SPA or not.
    – James
    Nov 9 at 21:45













up vote
0
down vote



accepted







up vote
0
down vote



accepted






A given socket.io connection belongs only to one particular page. When the user browses to a new page (assuming you're not dynamically loading new content into the same master page using a single-page-app (SPA) architecture), that socket.io connection is closed and the new page can then open a new socket.io connection (that will have a different socket.id).




I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?




No, not when the browser is actually loading a whole new page into the current window/tab.




The usual way to create some sort of ID that is persistent when you go from one page to the next is to put an ID in a cookie and then that cookie will be available on each new page the user browses to and will stay consistent from one page to the next.



If you are using express on the server, you can use express-session to automatically create a persistent session for each new user and you can even store data in that session object that will be available on each page the user requests.






share|improve this answer














A given socket.io connection belongs only to one particular page. When the user browses to a new page (assuming you're not dynamically loading new content into the same master page using a single-page-app (SPA) architecture), that socket.io connection is closed and the new page can then open a new socket.io connection (that will have a different socket.id).




I want to know if it is possible to reuse my socket.id in my different pages of my project to not lose the connection of my socket?




No, not when the browser is actually loading a whole new page into the current window/tab.




The usual way to create some sort of ID that is persistent when you go from one page to the next is to put an ID in a cookie and then that cookie will be available on each new page the user browses to and will stay consistent from one page to the next.



If you are using express on the server, you can use express-session to automatically create a persistent session for each new user and you can even store data in that session object that will be available on each page the user requests.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 21:04

























answered Nov 9 at 20:40









jfriend00

420k46531577




420k46531577











  • @James - I do plenty of cajoling and teaching of new users on the ways of stack overflow. Plenty. I understand that need. But, even when a question is not that well written I can sometimes only find one likely meaning so I attempt to help. There is no comment at all on the OP's question asking to clarify about SPA.
    – jfriend00
    Nov 9 at 21:19










  • there was one asking the OP to provide a MVP which I upvoted, would be enough to guage whether it was an SPA or not.
    – James
    Nov 9 at 21:45

















  • @James - I do plenty of cajoling and teaching of new users on the ways of stack overflow. Plenty. I understand that need. But, even when a question is not that well written I can sometimes only find one likely meaning so I attempt to help. There is no comment at all on the OP's question asking to clarify about SPA.
    – jfriend00
    Nov 9 at 21:19










  • there was one asking the OP to provide a MVP which I upvoted, would be enough to guage whether it was an SPA or not.
    – James
    Nov 9 at 21:45
















@James - I do plenty of cajoling and teaching of new users on the ways of stack overflow. Plenty. I understand that need. But, even when a question is not that well written I can sometimes only find one likely meaning so I attempt to help. There is no comment at all on the OP's question asking to clarify about SPA.
– jfriend00
Nov 9 at 21:19




@James - I do plenty of cajoling and teaching of new users on the ways of stack overflow. Plenty. I understand that need. But, even when a question is not that well written I can sometimes only find one likely meaning so I attempt to help. There is no comment at all on the OP's question asking to clarify about SPA.
– jfriend00
Nov 9 at 21:19












there was one asking the OP to provide a MVP which I upvoted, would be enough to guage whether it was an SPA or not.
– James
Nov 9 at 21:45





there was one asking the OP to provide a MVP which I upvoted, would be enough to guage whether it was an SPA or not.
– James
Nov 9 at 21:45


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53220778%2fsocket-io-multiple-pages%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo