Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use RPC over WebSocket?

Tags:

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

like image 535
zjffdu Avatar asked Jun 13 '17 00:06

zjffdu


People also ask

Does RPC use WebSocket?

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.

When should you not use a WebSocket?

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.

What is the benefit of using WebSocket over HTTP?

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.

Should I use WebSockets or rest?

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.


1 Answers

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.

like image 73
gzost Avatar answered Sep 30 '22 14:09

gzost