I have 2 components which need to communicate with each other in bidirectional way. For now I have 2 approaches, one is setting up RPC server in both side to establish the 2-way communication. Another is using websocket. Could anyone help me to compare the pros and cons of RPC and WebSocket ? Thanks
WebSocket is a message-based transport, while RPC is a communication pattern. If you want routed RPCs over WebSocket, then take a look at the WAMP protocol (http://wamp-proto.org). This avoids having to set up a server/opening a port on each component, and allows them to communicate from behind NATs.
Avoid using WebSockets if only a small number of messages will be sent or if the messaging is very infrequent. Unless the client must quickly receive or act upon updates, maintaining the open connection may be an unnecessary waste of resources.
Whereas HTTP relies on a client request to receive a response from the server for every exchange, WebSockets allow for full-duplex bidirectional communication. This enables the server to send real-time updates asynchronously, without requiring the client to submit a request each time.
WebSocket is ideal for a scenario where high loads are a part of the game, i.e. real-time scalable chat application, whereas REST is better fitted for occasional communication in a typical GET request scenario to call RESTful APIs.
WebSocket is a message-based transport, while RPC is a communication pattern. If you want routed RPCs over WebSocket, then take a look at the WAMP protocol (http://wamp-proto.org). This avoids having to set up a server/opening a port on each component, and allows them to communicate from behind NATs.
Full disclosure: I am deeply involved in the WAMP ecosystem, but the protocol is open, as are most of the implementations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With