Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can javascript receive socket request?

How can I make my javascript client application receive socket requests? I mean not response on request, but request itself.
Javascript is running in browser without HTML5.

The thing is that I want my web page to reload changed content but without the need of making request to the server each several minutes.
I hope that a server can make some request to javascript on the page, making it refresh the page. If not what could you suggest instead javascript in this scope.

like image 469
tsds Avatar asked Mar 26 '11 09:03

tsds


1 Answers

Many browsers that support HTML5 implement WebSocket interface. WebSocket allows two way communication, so browser and server can send requests. Check this post for more info What browsers support HTML5 WebSocket API?

If your browser doesn't support WebSockets you could try WebSocket emulation written in Flash/JS from this site https://github.com/gimite/web-socket-js

If this is also not suitable for you then the last option is "long polling". In this case browser ask server for some data and if server does not have any information available for the browser it doesn't send empty response. It holds the request and waits for new data to be available. Browser after receiving new data immediately ask server once again. Check these links for more information: http://en.wikipedia.org/wiki/Push_technology http://en.wikipedia.org/wiki/Comet_(programming)

like image 77
Zuljin Avatar answered Oct 20 '22 09:10

Zuljin