Links to articles would also be appreciated--I don't know the terminology to search for.
文章的链接也将受到赞赏 - 我不知道要搜索的术语。
I'm looking to learn how a web application can allow for server-to-client communications. I know the web was not designed for this and that it has been something of a hurdle, and am just wondering what the state of this is, and what the best practices are.
我正在研究Web应用程序如何允许服务器到客户端的通信。我知道网络不是为此而设计的,而且它一直是一个障碍,我只是想知道这是什么状态,以及最佳实践是什么。
An alternative is constant or occasional polling via ajax, but is it possible for web servers to maintain stateful connections to a web client?
另一种方法是通过ajax进行常规或偶尔轮询,但是Web服务器是否可以维护与Web客户端的状态连接?
Edit: Another way to ask this question is how does * tell a page that new posts are available for it to display that little bar at the top?
编辑:另一种问这个问题的方法是*如何告诉页面新帖子可用于在顶部显示那个小栏?
4 个解决方案
#1
5
* polls the server to check if there is more data.
*轮询服务器以检查是否有更多数据。
What you're looking for is Comet.
您正在寻找的是Comet。
#2
1
To get true two way communications from a browser you need to use a plugin technology like Silverlight, Flash, et al. Those plugins can create TCP connections that can establish a two way persistent connection with a server socket. Note that you can't really establish the TCP connection with the HTTP server so you'd have to create an additional server agent to do the communicating back to the browser.
要从浏览器获得真正的双向通信,您需要使用Silverlight,Flash等插件技术。这些插件可以创建TCP连接,可以与服务器套接字建立双向持久连接。请注意,您无法与HTTP服务器建立TCP连接,因此您必须创建其他服务器代理才能与浏览器进行通信。
Basically it's a completely differnet deployment model to what AJAX sites like *, Gmail etc. use. They all rely on the browser polling the server at set intervals.
基本上它是一个与*,Gmail等AJAX网站使用的完全不同的部署模型。它们都依赖于浏览器以设定的间隔轮询服务器。
#3
0
Web browsers really aren't set up to handle this sort of communication. The communication is a one way street where the web server is listening on a port (typically 80 or 443) for for information to be sent to it.
Web浏览器确实没有设置来处理这种通信。通信是单向路径,其中Web服务器正在侦听端口(通常为80或443)以便将信息发送给它。
I just read the link on comet, and it's interesting approach, but what has to be remembered is that it is still technically being opened by the client. The server is sending code for it to execute, but the browser is ultimately in control and determines when the server communicates with it.
我只是阅读了关于彗星的链接,这是一个有趣的方法,但必须记住的是它仍然在技术上被客户打开。服务器正在发送代码供其执行,但浏览器最终处于控制状态,并确定服务器何时与之通信。
With today's web browsers the server can never technically execute a message being sent to it without the help of the browser. Technically you might be able to get around that by executing some Active X control on the client machine...but I haven't tried it.
使用今天的Web浏览器,服务器无需技术上就可以在没有浏览器帮助的情况下执行发送给它的消息。从技术上讲,您可以通过在客户端计算机上执行一些Active X控件来解决这个问题...但我还没有尝试过。
#4
0
You can't, HTTP is stateless. A long time ago Netscape implemented HTTP Push but it wasn't a sucess.
你不能,HTTP是无国籍的。很久以前Netscape实现了HTTP Push,但它不是成功的。
I'd use polling with a web service or similar; no plugin (that is Flash, Java,Silverlight) will have rights in its sandbox to use raw sockets so it'll be a waste of time trying to implement it that way.
我会使用网络服务或类似的轮询;没有插件(即Flash,Java,Silverlight)将在其沙箱中拥有使用原始套接字的权限,因此尝试以这种方式实现它将浪费时间。
#1
5
* polls the server to check if there is more data.
*轮询服务器以检查是否有更多数据。
What you're looking for is Comet.
您正在寻找的是Comet。
#2
1
To get true two way communications from a browser you need to use a plugin technology like Silverlight, Flash, et al. Those plugins can create TCP connections that can establish a two way persistent connection with a server socket. Note that you can't really establish the TCP connection with the HTTP server so you'd have to create an additional server agent to do the communicating back to the browser.
要从浏览器获得真正的双向通信,您需要使用Silverlight,Flash等插件技术。这些插件可以创建TCP连接,可以与服务器套接字建立双向持久连接。请注意,您无法与HTTP服务器建立TCP连接,因此您必须创建其他服务器代理才能与浏览器进行通信。
Basically it's a completely differnet deployment model to what AJAX sites like *, Gmail etc. use. They all rely on the browser polling the server at set intervals.
基本上它是一个与*,Gmail等AJAX网站使用的完全不同的部署模型。它们都依赖于浏览器以设定的间隔轮询服务器。
#3
0
Web browsers really aren't set up to handle this sort of communication. The communication is a one way street where the web server is listening on a port (typically 80 or 443) for for information to be sent to it.
Web浏览器确实没有设置来处理这种通信。通信是单向路径,其中Web服务器正在侦听端口(通常为80或443)以便将信息发送给它。
I just read the link on comet, and it's interesting approach, but what has to be remembered is that it is still technically being opened by the client. The server is sending code for it to execute, but the browser is ultimately in control and determines when the server communicates with it.
我只是阅读了关于彗星的链接,这是一个有趣的方法,但必须记住的是它仍然在技术上被客户打开。服务器正在发送代码供其执行,但浏览器最终处于控制状态,并确定服务器何时与之通信。
With today's web browsers the server can never technically execute a message being sent to it without the help of the browser. Technically you might be able to get around that by executing some Active X control on the client machine...but I haven't tried it.
使用今天的Web浏览器,服务器无需技术上就可以在没有浏览器帮助的情况下执行发送给它的消息。从技术上讲,您可以通过在客户端计算机上执行一些Active X控件来解决这个问题...但我还没有尝试过。
#4
0
You can't, HTTP is stateless. A long time ago Netscape implemented HTTP Push but it wasn't a sucess.
你不能,HTTP是无国籍的。很久以前Netscape实现了HTTP Push,但它不是成功的。
I'd use polling with a web service or similar; no plugin (that is Flash, Java,Silverlight) will have rights in its sandbox to use raw sockets so it'll be a waste of time trying to implement it that way.
我会使用网络服务或类似的轮询;没有插件(即Flash,Java,Silverlight)将在其沙箱中拥有使用原始套接字的权限,因此尝试以这种方式实现它将浪费时间。