S
S
Space2014-03-13 12:04:48
JavaScript
Space, 2014-03-13 12:04:48

How to connect socket on all pages?

Hello. I am logging into php+js. Is it logical for a user to make an online column in the database with the value 1 (online) and 0 (offline), and to change this column when entering the site, and reset it when leaving? But, of course, it doesn't work that way. In terms of the fact that the output may not be pressed, for example. I am using node.js.

How can I make sure that, regardless of the site page, if cookies are stored, then a message is sent to the database in the node with changes made to the online column? I have an example of a chat, I send data by sockets (socket.io), but I specify the path to this socket on the page of this chat.

How can I make the node detect this on all pages of the site? Every time to connect on all pages a socket or how? I hope I explained clearly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lxfr, 2014-03-13
@ruslite

Of course, connect the socket on all pages, for example.

S
Sergey, 2014-03-13
Protko @Fesor

with your logic, websockets are not needed, or only websockets without databases are needed. You can bind a user id to connections, and periodically track which connections are currently dead, thus determining whether a user is online or not.
But in general, if I were you, I would once again look at how such tasks are usually solved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question