Is there a way to make a live updating server?
So I have a question: Can I make a webpage that updates live?
So, say, I have a user click a button, and the number is displayed on their screen every time he clicks it. Is it possible for another user to have the same setup, however see how many times the first person has clicked the button live?
If so, please give me a tutorial for this, as I'm not the best at coding quite yet. Thanks a lot!
Voters
Coder100
Yes. Here is how i did it:
- Set up server
- Set up html
- Set up socket.io
- Listen for handlers
- Success!
All of it is documented. Just look at my code right here: https://repl.it/@coder100/4rohilpatel
The ‘game’ is here:
https://4rohilpatel.coder100.repl.co/
Mark as correct answer if this was helpful!
Also, as a plus, the click amount saves until the repl shuts down after 1 hour of no inactivity!
AdCharity
btw if you don't want to deal with all that: use Firebase
You need an Expressjs server with websockets set up to increment a database value each time. Do you have any experience in Expressjs or websockets?
Not really @Vandesm14
@RohilPatel Are you more familiar with Python web servers?
No, I am most fluent in Html, js, and css [email protected]
@RohilPatel Ah. So I suggest that you learn Expressjs in order to get a server up and running. Once you have that, feel free to contact me on Discord Vandesm14#3364. I'll be more than happy to help you get the web app set up.
@Vandesm14 I friended u on discord. And I may need help now making a server. Could you help with that?
@RohilPatel Sure. For now though, mark my comment as the answer
Don't worry, I'll be helping you on discord. It's just so others know this is answered.
@Vandesm14 tbh I prefer http for anything thats not sustained
Explain.... @MrEconomical
@RohilPatel um well websockets are usually used when connections need to be sustained and messages need to be sent back and forth very fast, for example something like a multiplayer game might use websockets. HTTP requests are just one time, you send it and you get a response.
@MrEconomical Http? Expressjs is an http server for NodeJS.
@Vandesm14 my bad
@MrEconomical do you have any examples?
@RohilPatel something like this
client: https://repl.it/@MrEconomical/xmlreq-testing
server: https://repl.it/@MrEconomical/http-server
if you hit run on the client you can see it gets something back from the server
@RohilPatel that client was made in node.js the same thing would work in normal html / css / js except you don't need require() because xmlhttprequests are a built-in thing
@MrEconomical Yes, polling is also a thing. Websockets are better as you're not using as much resources on the client to constantly poll the server for new data. Also, http, like you said, is generally a one-time thing. It's not meant for live updates, which is the goal here.
@Vandesm14 oh I thought all he needed was updating a number once
@MrEconomical so are you saying that I can import data from two different websites?
@RohilPatel disregard everything I said I was just mentioning an alternative that doesn't seem to be good in your case
@MrEconomical ok