Create an array that stores all client sockets, a socket created when users log in.
If you use the socket.io module to control the connection between clients and the server, you do not need to worry about the structure or the stored clients, since it will be managed for you in the background. It also offers various backups (including long polling) if client browsers do not support advanced vehicles such as WebSockets.
One more thing, how can I refresh a web page or view, if something is updated in the database, I poll the server every time?
DO NOT access the server every second, as transports such as long polling and WebSockets have been introduced to AVOID this. Since you will have constant communication between the client and the server with socket.io (which use methods and technologies, such as long polling or WebSockets), you can easily create an event system that updates or notifies specific clients about the changes when this happens .
I am using a MySQL database, should I use Redis instead?
Redis is a very good key / value repository for real-time data, frequently updated, which does not require a complex query. If you need advanced query support for your data, try, for example, looking at MongoDB .
source share