当前位置: 动力学知识库 > 问答 > 编程问答 >

Node.JS Multiple User inteaction

问题描述:

I have just started looking into Node.JS and am very interested in finding out how and if it is possible for multiple users to interact.

For now I am just trying to get a static HTML page to increment a variable say a = 0; Each time a is clicked with a very simple onclick listener.

What I envisage and someone more knowledgeable can tell me if it is possible is. To open that page on two devices. Say my laptop and my phone and be able to click the div incrementing the variable and the number to update on both screens.

Is this something simple? (How "simple" is this?. What would it entail, can it be done without a database and just javascript? Can anyone point me in a direction of research as currently I'm feeling my way around with no direction) I know normally this would be a database driven feature, but I do not need persistence. Literally only while the page is open does the value need to be "remembered".

网友答案:

You should try with socket.io.

With the functions socket.emit and socket.on you can trigger event server-side from client-side and vice-versa.

here is the repo with a simple chat example, hope this will help you

分享给朋友:
您可能感兴趣的文章:
随机阅读: