1

Hi i am creating a social networking site for my college. It is based on PHP. To create websocket connection to retrieve notifications and set up chat system using node.js with connect and socket.io frameworks.

I started a socket connection on one page which i want to resume the same connection with same id on other pages served by web server.

And destroy the socket on logout and like with session in PHP.

Amit Chowdhury
  • 623
  • 1
  • 7
  • 22
zerocool
  • 316
  • 1
  • 4
  • 19
  • Could you show us what you have tried so far? – Longball27 Jun 27 '13 at 05:06
  • sir i have not written any code for implementing websockets using node.js in my application yet But i was successfully able to create a chat room in another application Problem is i have some 15 pages that user can access if i create connect to socket on one page i have to resume that connection on another page without have to restarting the connection – zerocool Jun 27 '13 at 05:25
  • and its not entirely based on node.js all the pages are served by PHP so i have a problem resuming the connection on to other pages – zerocool Jun 27 '13 at 05:45

2 Answers2

0

Another topic with similar problem: How to maintain a WebSockets connection between pages?

I'm currently working with same implemation and I did overcome this problem on the server side code having user class that have list of connections that belongs to that user. First client will connect to the server, after that client will register itself using username and given random hash(Extra security against phishing) and the server uses this information to determite who is this client.

And when logging out send destroy command also to websocket server so it knows to destroy this user from memory.

Community
  • 1
  • 1
Cultti
  • 107
  • 4
0

You need to maintain session when socket goes through handshake process.
By restoring session - you will restore related data to that session as well.
Do not store data related to user in socket object, and socket.id is not reliable for identification - only for connection.

Additionally you could store session data in redis and then collect it using PHP and node, in order to have one session data storage but with shared applications.

moka
  • 22,846
  • 4
  • 51
  • 67