I'm writing a chat application from scratch, and I'm trying to figure out the best way to retrieve messages from the server in real time. I've done a fair amount of research, and have come up with this: I could use web sockets, and I've seen it done before successfully. I could use long polling, but I'm wondering if that places greater stress on the server, or maybe is just not right for a chat application. I could poll the server every second, but that just seems like a waste of bandwidth. Suggestions? Thank you!
What's the best way to retrieve messages from the server for a chat application
202 views Asked by Christopher Shroba At
2
There are 2 answers
0
On
What? Do you need to and from a database on a dedicated server? I would recommend Ajax with JavaScript or jQuery but i like to do my own coding so JavaScript. If your showing data back and forth match i would probably use MySQL.
For example to query up the last known query if matches current then would not be updated. If doesn't match loop up from last to rent match would be DESC if in Order by type. Anyways... Hope this helps you decide on what you should use.
Although this is what is common on games, blogs, forums, chats with MySQL/SQL.
The websocket protocol is ideal for something like a chat application for several reasons.
So to answer your question. You should definitely go with web sockets. Since you lack traditional headers, you will have to do a bit of work when it comes to formatting the messages sent over the connection, but the efficiency is well worth the minimal effort it takes to set up your messaging model.