How can I make my javascript client application rec开发者_开发知识库eive 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.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)
Yes and No.
No
Javascript running in a browser environment can't listen to sockets since it's running in a sandbox with limited capabilities.
Yes
However, JS is a full fledged programming language, so if you have it running in an environment where it is not crippled yes, it can do that and more.
A nice example is node.js - http://nodejs.org/
Wiki page - http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pages
精彩评论