How to make an instant chat ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to make an instant chat ?

What is the method to make an instant chat without keeping messages into a database ? So people connect for example at 12h and they are able to see all the message posted after 12h until that they leave the page

24th Aug 2017, 8:52 PM
Αητοιπe
Αητοιπe - avatar
6 Answers
+ 11
you can congifure listeners with socket.io the server can hold the messages for as long as it'a running i'd suggest you experiment with socket.io and node.js and if you want to run a webserver you can host small apps on heroku here's a small demo i did a while back https://github.com/bureyburey/tictactoe-ng-express-socketio hosted at heroku: https://tictactoe-ng-express-socketio.herokuapp.com/#!/home
24th Aug 2017, 9:28 PM
Burey
Burey - avatar
+ 7
research websockets mainly socket.io goodluck ;)
24th Aug 2017, 9:20 PM
Burey
Burey - avatar
+ 4
I think you'll need the devices to bypass a server and connect directly, so you'll probably need some static ip addresses or someway of finding the ip of the devices before connection. It's quite advanced stuff and a bit beyond me. I'd stick with a database and server, it's much simpler. Maybe someone else can suggest something better. Any reason why you don't want to use a database?
24th Aug 2017, 9:13 PM
Bagshot
Bagshot - avatar
+ 4
@Antoine, if you research ajax you'll see that you don't need to refresh the page when new messages appear. Good luck, mate.
24th Aug 2017, 9:50 PM
Bagshot
Bagshot - avatar
+ 2
@Burey thanks
24th Aug 2017, 9:22 PM
Αητοιπe
Αητοιπe - avatar
+ 1
Firstly thank you for your answer. I can use a database but I don't want to keep all the messages. I can delete the messages if they are to old but I just wanted to know if there is a way to make this without creating new lines on sql database deleting lines... An other question, for a chat we need to refresh the page everytime we get a new message, didn't it ? I just don't know why in php I can refresh the part with my chat not the entire webpage
24th Aug 2017, 9:22 PM
Αητοιπe
Αητοιπe - avatar