如上图所示,来自Bayeux客户端BC的Bayeux消息M0,到达Bayeux服务端BS,是通过从用户代理U经由代理P到原始服务器O的HTTP请求传输的。消息M0被发送,并期望一个Bayeux事件要从服务端被传送到客户端,Bayeux服务端在发送响应前会等待这样的事件。Bayeux事件E在HTTP响应中由Bayeux消息M1发送。M1可能包含0个,1个或多个到Bayeux客户端的Bayeux事件。
The transport used may terminate the HTTP response after delivery of M1 or use techniques to leave the response open and stream additional messages to the client.
所使用的传输方式在M1发送后可能中断HTTP响应,或者使用技术保持响应打开并传递到客户端的其他消息。
1.4.5.i 轮询传输Polling transportsPolling transports will always terminate the HTTP response after sending all available Bayeux messages.
轮询传输方式总会在发送所有可用Bayeux消息后中断HTTP响应。
BC ---------- U ---------- P ------------ O ---------- BS
| ---M0---> | | | |
| | --- HTTP request(M0) ---> | |
| | | | ----M0---> |
~ ~ ~ ~ ~ wait
| | | | <--M1(E)-- |
| | <--HTTP response(M1(E))-- | |
| <--M1(E)-- | | | |
| ---M2---> | | | |
| | --- HTTP request(M2) ---> | |
| | | | ----M2---> |
~ ~ ~ ~ ~ wait
On receipt of the HTTP response containing M1, the Bayeux client issues a new Bayeux message M2 either immediately or after an interval in anticipation of more events to be delivered from server to client. Bayeux implementations are required to support a specific style of polling transport called "long polling" (see sec 6.1).
当收到包含M1的HTTP响应时,Bayeux客户端立即发出一个新的Bayeux消息,或者在一个从服务端到客户端被发送的更多事件的期望间隔后发出。Bayeux实现要求支持一个被称为“长轮询”的特定风格的轮询传输。
1.4.5.ii 流传输Streaming transportsSome Bayeux transports use a streaming technique (also called a forever response) that allows multiple messages to be sent over the same HTTP response:
有些Bayeux传输方式使用流技术(也称为永久响应),流技术允许多个消息通过同一个HTTP响应发送。
BC ---------- U ---------- P ------------ O ---------- BS
| ---M0---> | | | |
| | --- HTTP request(M0) ---> | |
| | | | ----M0---> |
~ ~ ~ ~ ~ wait
| | | | <--M1(E0)- |
| | <--HTTP response(M1(E0))- | |
| <--M1(E0)- | | | |
~ ~ ~ ~ ~ wait
| | | | <--M1(E1)- |
| | <----(M1(E1))------------ | |
| <--M1(E1)- | | | |
~ ~ ~ ~ ~ wait
Streaming techniques avoid the latency and extra messaging of anticipatory requests, but are subject to the implementation of user agents and proxies as they requires incomplete HTTP responses to be delivered to the Bayeux client.
流技术避免延时和额外的信息预先请求,但是对用户代理和代理的实现有影响,因为他们需要不完整的HTTP响应以发送到Bayeux客户端。
1.4.6. 双连接运作Two connection operationIn order to achieve bi-directional communications, a Bayeux client will use two HTTP connections to a Bayeux server so that both server to client and client to server messaging may occur asynchronously:
为了实现双向通信,Bayeux客户端会使用两个HTTP连接连接到Bayeux服务端,因此服务端到客户端和客户端到服务端的消息传递可能异步产生:
BC ---------- U ---------- P ------------ O ---------- BS
| ---M0---> | | | |
| | ------ req0(M0) --------> | |
| | | | ----M0---> |
~ ~ ~ ~ ~ wait
| --M1(E1)-> | | | |
| | ----- req1(M1(E1))------> | |
| | | | --M1(E1)-> |
| | | | <---M2---- |
| | <---- resp1(M2)---------- | |
| <---M2--- | | | |
~ ~ ~ ~ ~ wait
| | | | <-M3(E2)-- |
| | <-----resp2(M3(E2))------ | |
| <-M3(E2)-- | | | |
| ---M4---> | | | |
| | ------req3(M4)----------> | |
| | | | ----M4---> |
~ ~ ~ ~ ~ wait
HTTP requests req0 and req1 are sent on different TCP/IP connections, so that the response to req1 may be sent before the response to req0. Implementations MUST control HTTP pipelining so that req1 does not get queued behind req0 and thus enforce an ordering of responses.
HTTP请求req0和req1在不同的TCP/IP连接上发送,因此req1的响应可能在req0的响应前被发送。实现必须控制HTTP流水线处理,因此req1不能在req0前被排队,因而能强制响应的顺序。
1.4.7. 连接协商Connection NegotiationBayeux connections are negotiated between client and server with handshake messages that allow the connection type, authentication and other parameters to be agreed upon between the client and the server.
Bayeux连接通过握手消息在服务端和客户端之间协商允许的连接类型,认证和其他在客户端和服务端约定的参数。