It is true that the term "comet" is a term for these technologies, but the Bayeux protocol is used only by a few implementations. The Comet technique can use any protocol required; Bayeux is one of them.
Having said that, there are two main differences between the asynchronous servlet solution and the Comet + Bayeux solution.
The first difference is that the Comet + Bayeux solution is independent of the protocol that Bayeux passes. The CometD project has plug-in transports for clients and servers that Bayeux can carry. You can port it using HTTP, with Bayeux being the content of the POST request, but you can also port it using WebSocket, with Bayeux being the payload of the WebSocket message. If you use async servlets, you cannot use WebSocket, which is more efficient than HTTP.
The second difference is that the async server has only HTTP, and you need more than to handle remote Comet clients.
For example, you can uniquely identify customers, so 2 tabs for the same page lead to 2 different customers. To do this, you need to add a “property” to the request servlet of the asynchronous call, call it sessionId .
Then you want to be able to authenticate the client; only authenticated clients can get sessionId . But in order to distinguish between the first authentication requests and other subsequent requests that are already authenticated, you need another property, for example messageType .
Then you want to be able to quickly notify of a disconnection due to network loss or other connection problems; therefore, you need to come up with a solution with a heart rhythm so that if the heart beats, you know that the connection is alive, if it does not beat, you know it is dead and perform rescue actions.
Then you need to disable the features. And so on.
You quickly realize that you are building another protocol on top of HTTP.
At this point, it’s best to use an existing protocol such as Bayeux, and proven solutions such as CometD (which is based on Comet methods using the Bayeux protocol), which gives you:
- Java and JavaScript client libraries with simple yet powerful APIs
- A Java server library to execute your application logic without having to process low-level details such as HTTP or WebSocket through annotated services.
- Transport connectivity, both client and server
- Bayeux Protocol Extensibility
- lazy messages
- Clustering
- Highest performance
- Future proof: CometD users didn’t change the line of code before WebSocket to take advantage of WebSocket - all the magic was implemented in libraries
- Based on standards
- Designed and maintained by web protocol experts.
- Extended documentation
- I can continue, but you understand :)
You do not want to use a low-level solution that only connects you to HTTP. You want to use a higher-level solution that abstracts your application from the Comet technique used and the protocol that Bayeux passes so that your application can be written once and use future technology improvements. As an example of technology advancement, CometD worked well before asynchronous servlets got into the picture, and now using the asynchronous servlet just became more scalable, and so your application without having to change one line in the application.
Using a higher-level solution, you can focus on your application, and not on the details of how to write an asynchronous servlet correctly (and it’s not as easy as you might think).
The answer to your question may be this: you use Comet + Bayeux because you want to stand on the shoulder of the giants .