简体   繁体   中英

what are the possible ways of two-way communication between web-service and web application

I have a web application and a web-service that needs to communicate with each other. This communication has to be a two way communication because web-application can send events occured at interface to web-service. And web-service can send the events recieved by third party to web-application part. So, what design should I follow for doing this? How to make this communication a two-way communication?

Regards, Anshul

You can do this by employing the Comet model (called sometimes reversed AJAX). It is implemented by long-polling or opening a persistent connection to the webservice.

In long-polling mode, the client opens a connection to the webservice and waits for the server's response. When there is an event coming from the server to the client, the server simply responds using that pre-existing connection and closes the connection, then the client reads the response, and immediately opens a new connection to listen for more events.

In the streaming mode, the connection is persistent, not closed after each server event. HTTP/1.1 chunked responses with hidden iframe can be used to accomplish this.

Regardless of the client-side implementation, beware using Comet may cause an excessive number of open connections on the server side. You should take that into account when deciding on the web-server stack / web framework - ideally it should use non-blocking I/O and continuations to decouple long connections from server's threads.

Some web frameworks have Comet support already built in: Play and Lift

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM