The nature of websockets allow realtime data transfer between two peers in “realtime”. This mechanism is perfect for exchanging events without relation to each other. But what if you want to ask your peer for some specific response and wait until this particular response arrives?
This pattern is well-known under the name Request-Reply or Request-Response and builds the basis for todays HTTP communication on the web. Following JavaScript code shows how the Node.JS API implements this pattern to request some HTTP response from a webserver:
As soon as a response is available, the callback function armed with the response object gets executed and the awaited data is processed.
Using websockets, you do not have this mechanism built-in since there is not really a response which has to follow on a request. More precisely, there is not even a thing called request: You exchange data with no relation to each other.
Primus Responder resolves this situation while being a plugin for the realtime communication wrapper Primus. It allows to request the opposite peer for a response using a simple API known from other libraries.
Your new post is loading...