Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><em>In the examples below the client is the browser and the server is the webserver hosting the website.</em></p> <p>Before you can understand these technologies, you have to understand <em>classic</em> HTTP web traffic first.</p> <h2>Regular HTTP:</h2> <ol> <li>A client requests a webpage from a server.</li> <li>The server calculates the response</li> <li>The server sends the response to the client. </li> </ol> <p><img src="https://i.stack.imgur.com/TK1ZG.png" alt="HTTP"></p> <h2>Ajax Polling:</h2> <ol> <li>A client requests a webpage from a server using regular HTTP (see HTTP above).</li> <li>The client receives the requested webpage and executes the JavaScript on the page which requests a file from the server at regular intervals (e.g. 0.5 seconds).</li> <li>The server calculates each response and sends it back, just like normal HTTP traffic.</li> </ol> <p><img src="https://i.stack.imgur.com/qlMEU.png" alt="Ajax Polling"></p> <h2>Ajax Long-Polling:</h2> <ol> <li>A client requests a webpage from a server using regular HTTP (see HTTP above).</li> <li>The client receives the requested webpage and executes the JavaScript on the page which requests a file from the server.</li> <li>The server does not immediately respond with the requested information but waits until there's <strong>new</strong> information available.</li> <li>When there's new information available, the server responds with the new information.</li> <li>The client receives the new information and immediately sends another request to the server, re-starting the process. </li> </ol> <p><img src="https://i.stack.imgur.com/zLnOU.png" alt="Ajax Long-Polling"></p> <h2>HTML5 Server Sent Events (SSE) / EventSource:</h2> <ol> <li>A client requests a webpage from a server using regular HTTP (see HTTP above).</li> <li>The client receives the requested webpage and executes the JavaScript on the page which opens a connection to the server.</li> <li><p>The server sends an event to the client when there's new information available. </p> <ul> <li>Real-time traffic from server to client, mostly that's what you'll need</li> <li>You'll want to use a server that has an event loop</li> <li>Not possible to connect with a server from another domain</li> <li>If you want to read more, I found these very useful: <a href="https://developer.mozilla.org/en-US/docs/Server-sent_events/Using_server-sent_events" rel="noreferrer">(article)</a>, <a href="http://html5doctor.com/server-sent-events/#api" rel="noreferrer">(article)</a>, <a href="http://www.html5rocks.com/en/tutorials/eventsource/basics/" rel="noreferrer">(article)</a>, <a href="http://jaxenter.com/tutorial-jsf-2-and-html5-server-sent-events-42932.html" rel="noreferrer">(tutorial)</a>.</li> </ul></li> </ol> <p><img src="https://i.stack.imgur.com/ziR5h.png" alt="HTML5 SSE"></p> <h2>HTML5 Websockets:</h2> <ol> <li>A client requests a webpage from a server using regular http (see HTTP above).</li> <li>The client receives the requested webpage and executes the JavaScript on the page which opens a connection with the server.</li> <li><p>The server and the client can now send each other messages when new data (on either side) is available.</p> <ul> <li>Real-time traffic from the server to the client <strong>and</strong> from the client to the server</li> <li>You'll want to use a server that has an event loop</li> <li>With WebSockets it is possible to connect with a server from another domain.</li> <li>It is also possible to use a third party hosted websocket server, for example <a href="http://pusher.com/" rel="noreferrer">Pusher</a> or <a href="http://www.leggetter.co.uk/real-time-web-technologies-guide" rel="noreferrer">others</a>. This way you'll only have to implement the client side, which is very easy!</li> <li>If you want to read more, I found these very useful: (<a href="http://www.developerfusion.com/article/143158/an-introduction-to-websockets/" rel="noreferrer">article</a>), <a href="https://developer.mozilla.org/en-US/docs/WebSockets/Writing_WebSocket_client_applications" rel="noreferrer">(article)</a> (<a href="http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/" rel="noreferrer">tutorial</a>).</li> </ul></li> </ol> <p><img src="https://i.stack.imgur.com/CgDlc.png" alt="HTML5 WebSockets"></p> <h2>Comet:</h2> <p>Comet is a collection of techniques prior to HTML5 which use streaming and long-polling to achieve real time applications. Read more on <a href="http://en.wikipedia.org/wiki/Comet_%28programming%29" rel="noreferrer">wikipedia</a> or <a href="http://www.ibm.com/developerworks/web/library/wa-reverseajax1/index.html" rel="noreferrer">this</a> article.</p> <hr> <blockquote> <p>Now, which one of them should I use for a realtime app (that I need to code). I have been hearing a lot about websockets (with socket.io [a node.js library]) but why not PHP ?</p> </blockquote> <p>You can use PHP with WebSockets, check out <a href="http://socketo.me/" rel="noreferrer">Ratchet</a>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload