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
node.js socket.io chat
add a comment |
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
node.js socket.io chat
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
add a comment |
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
node.js socket.io chat
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
node.js socket.io chat
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
add a comment |
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
add a comment |
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.
@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
add a comment |
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.
@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
add a comment |
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.
@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
add a comment |
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.
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.
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
add a comment |
@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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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