My website allows users to send messages to one another; however, the only way to see their new messages is to refresh the page. Is there any way to notify the user via any method?
Thanks for your time
There are 2 mechanism in HTML5, I believe, but I'm only going to point you at one for the moment: Web Workers.<URL: http://www.htmlgoodies.com/html5/javascript/working-with-web-workers-in-html5-powered-web-pages.html>
<URL:http://www.htmlgoodies.com/HTML5/client/introduction-to-html5-web-workers-the-javascript-multi-threading-approach.html>
<URL:http://www.htmlgoodies.com/html5/other/html5-tech-shared-web-workers-help-spread-the-news.html>
With this mechanism, you'd spawn a web worker to do jquery/ajax to check when it was time to replace the content. A couple of the examples calculate Pi, and paste the results into the main page.
There is also web sockets in HTML5.
<URL:http://www.htmlgoodies.com/html5/tutorials/making-html5-websockets-work.html>
Gluon/contrib has websocket_messaging.py.
On Wednesday, November 2, 2016 at 7:52:05 PM UTC-4, Dave S wrote:There are 2 mechanism in HTML5, I believe, but I'm only going to point you at one for the moment: Web Workers.<URL: http://www.htmlgoodies.com/html5/javascript/working-with-web-workers-in-html5-powered-web-pages.html>
<URL:http://www.htmlgoodies.com/HTML5/client/introduction-to-html5-web-workers-the-javascript-multi-threading-approach.html>
<URL:http://www.htmlgoodies.com/html5/other/html5-tech-shared-web-workers-help-spread-the-news.html>
With this mechanism, you'd spawn a web worker to do jquery/ajax to check when it was time to replace the content. A couple of the examples calculate Pi, and paste the results into the main page.
This approach is "short polling" (i.e., polling the server with quick requests at some interval to check for updates). Note, there is no particular reason this must be done with a web worker -- you can simply do it from the main web page, as it has been done since long before web workers existed.
The idea is simply to keep making Ajax requests at regular intervals (e.g., every second). This approach might be fine, though depending on how many users are connected and how frequently they are checking, the server could get overwhelmed with requests. To reduce the load, you can decrease the request frequency, but then you increase the average latency between when a message is sent and when the recipient receives it.
There is also web sockets in HTML5.
<URL:http://www.htmlgoodies.com/html5/tutorials/making-html5-websockets-work.html>
Gluon/contrib has websocket_messaging.py.
To handle the shortcomings of "short polling", you can instead use websockets (or long-polling, which maintains a long-held HTTP connection with the server until a new message is received). However, you need a web server and application that can handle many long-held open connections. To address this need, web2py includes websocket_messaging.py, as noted above -- it makes use of the Tornado web server to handle the websocket connections. You can also use various realtime messaging services (e.g., Fanout), or something like Pushpin (an open source proxy server used by Fanout), which is probably a bit more robust and full-featured than websocket_messaging.py.
Anthony
Thanks for such a thorough response, Anthony!Long polling seems to be the way to go for my website. I've been reading up on the tornado web socket all day.I'm nearing 100 users on my website and i believe that speed will be a problem eventually. I'm deployed to python anywhere like you suggested; however, i am using sqlite still. As of now, everything is working and i've received no complaints on performance. Will there be a problem with long polling while using sqlite?
With this mechanism, you'd spawn a web worker to do jquery/ajax to check when it was time to replace the content. A couple of the examples calculate Pi, and paste the results into the main page.
This approach is "short polling" (i.e., polling the server with quick requests at some interval to check for updates). Note, there is no particular reason this must be done with a web worker -- you can simply do it from the main web page, as it has been done since long before web workers existed.
The idea I was applying was keeping the main page quiet, although Google News has used refresh interval to update the entire main page.
Web workers give you a thicker curtain to draw over the checkers, than does a LOAD/jquery/ajax in a timer loop on the main page.
Thanks for both of you guys time.
I've been thinking about trying https://pusher.com/