How to track users' data when using web sockets and Ratchet?

Posted In PHP
  • lincon-lincon 5 months ago
    Hello everyone,,
    I'm starting to use Ratchet for my first-ever web sockets implementation. I'm converting from Ajax. In my Ajax model, I store the user's username, plus [https://showbox.bio](https://showbox.bio/) a bunch of variables being used across the application, in the session. With sockets, the socket server is a single instance running on its own, so can't use the session global. How do I track users, given [https://tutuapp.uno/](https://tutuapp.uno/) that the $connection->resourceId [https://vidmate.vet/](https://vidmate.vet/) variable Ratchet offers can't be trusted to refer to the same user over the lifetime of the client's use of my website?
    
    So far, my only idea is to generate a long string of random letters and numbers in my onOpen() function, and send that to the client, which will save it. Any message from the client will then include the "key" the server gave it, thus identifying which client it is. If the client receives a new key, when a connection drops and is re-established, the new key is ignored and the previous one used instead. That should let me keep the user's data associated with the right user.
    
    Is there a better way to do this? Is there anything about all this that I'm overlooking? Thanks for any ideas.
    

    Hello everyone,, I'm starting to use Ratchet for my first-ever web sockets implementation. I'm converting from Ajax. In my Ajax model, I store the user's username, plus https://showbox.bio a bunch of variables being used across the application, in the session. With sockets, the socket server is a single instance running on its own, so can't use the session global. How do I track users, given https://tutuapp.uno/ that the $connection->resourceId https://vidmate.vet/ variable Ratchet offers can't be trusted to refer to the same user over the lifetime of the client's use of my website?

    So far, my only idea is to generate a long string of random letters and numbers in my onOpen() function, and send that to the client, which will save it. Any message from the client will then include the "key" the server gave it, thus identifying which client it is. If the client receives a new key, when a connection drops and is re-established, the new key is ignored and the previous one used instead. That should let me keep the user's data associated with the right user.

    Is there a better way to do this? Is there anything about all this that I'm overlooking? Thanks for any ideas.

  • susan-byrd 1 week ago
    Such an extraordinary instructive blog for the understudies to improve their investigation propensity and get help identified with their examination but now [best essays uk](https://www.ukbesteessays.com/) help me a lot for the compilation of work. understudies consistently look for direction and data to stay in good shape and to be succesful. These online sites are doing their best in helping them.

    Such an extraordinary instructive blog for the understudies to improve their investigation propensity and get help identified with their examination but now best essays uk help me a lot for the compilation of work. understudies consistently look for direction and data to stay in good shape and to be succesful. These online sites are doing their best in helping them.

Please login or signup to leave a response.

Login

or Sign Up

Sign Up

or Login
×
Want to create your own SAAS?

I can teach you to create your own Software as a Service. Click here to learn more!

Visit SAAS Adventure!