Answer the question
In order to leave comments, you need to log in
Web server on Node.js. How to organize and control a websocket listening service for each active user?
And so, there is a certain mobile application.
The user registers and logs in.
To continue working with the application, he needs to save the key. As soon as the key enters the database, the server starts listening to the web socket for this user. Data from the socket is processed and sent to the user in the form of notifications.
The problem is that while the server is running, sometimes you need to stop listening for some user, restart the socket, or open a new one. And for me, as a person who came from the world of statically typed languages and mobile development, it’s a little hard to get into the organization of such processes in a node.
I would be grateful for any answer or advice.
Answer the question
In order to leave comments, you need to log in
If you care about static typing, then you should look into Typescript and ts-node .
In fact, everything is done quite simply when using JWT. Here is an example https://github.com/auth0-community/auth0-socketio-jwt
This will help you get into the topic https://learn.javascript.ru/screencast/nodejs#node...
The socket will stand as long as it is needed on the server, and on the client, with an inactive connection (without data transfer), the connection is reset, after a reboot it appears. I don't know why you need sockets in the application if it's enough to use req/res./
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question