WebSockets Differences between WebSockets and AJAX example getting notification


Example

Ajax :

  1. New request :
    • Client sends request : Server , Do you have new notification ?
    • Server sends response : Client , NO
    • connection ends
  2. New request :
    • Client sends request : Server , Do you have new notification ?
    • Server sends response : Client , NO
    • connection ends
  3. New request :
    • Client sends request : Server , Do you have new notification ?
    • Server sends response : Client , NO
    • connection ends
  4. New request :
    • Client sends request : Server , Do you have new notification ?
    • Server sends response : Client , Yes here you are
    • connection ends

you see that there is number of useless requests !

web-socket

  • connection established :
  • client says : Server , Do you have new notification ?

after xx time passed

  • Server says : Yes I have

after xx time passed

  • Server says : Yes I have
  • Client says : Server , send new email if I have

after xx time passed

  • Server says : now you got new email

now the it's clear that with web-socket we won't have useless requests