Home  >  Article  >  Web Front-end  >  What is RPC communication in Node.js? What is the difference between it and Ajax?

What is RPC communication in Node.js? What is the difference between it and Ajax?

青灯夜游
青灯夜游forward
2021-11-08 09:56:342432browse

This article will take you to understand RPC communication and introduce the similarities and differences between RPC and Ajax. I hope it will be helpful to everyone!

What is RPC communication in Node.js? What is the difference between it and Ajax?

What is RPC communication

Preface

For back-end personnel, RPC communication is very familiar and easy Things to understand, but for front-end personnel like me, RPC is relatively unfamiliar and it is relatively difficult to understand. Regarding this problem, let's try it today and understand RPC communication from the front-end perspective. [Recommended learning: "nodejs Tutorial"]

RPC and Ajax

RPC and Ajax are very similar, and there are many similarities between them. For example:

  • is a communication between two computers

  • The data format will be agreed upon

The difference between RPC and Ajax:

  • is not necessarily based on DNS as an addressing service

  • The application layer protocol is generally not used HTTP protocol

  • Based on TCP or UDP protocol

Let’s talk about the differences between them one by one:

1. Differences in addressing servers

Ajax uses DNS as the addressing server

The URL that Ajax initiates a request is generally like this, For example: HTTP://domain name/path, but the communication between computers relies on IP instead of domain name, so an addressing server is needed to find the IP corresponding to the domain name, which is what Ajax uses. DNS serves as the addressing server. After obtaining the IP address, the browser finds the corresponding server based on the IP address, and then the server returns the data to the browser. The process is as shown below:

What is RPC communication in Node.js? What is the difference between it and Ajax?

RPC provides addressing services through a specific server

RPC is similar to the parsing process of Ajax. But it does not use DNS to address the server, and it uses a certain ID to find the corresponding IP. For example: Alibaba’s ID is similar to VIP.

What is RPC communication in Node.js? What is the difference between it and Ajax?

2. TCP communication method

The browser uses TCP to follow the HTTP specification, but there are many ways to use TCP with RPC :
1.Simplex communication
2.Half-duplex communication
3.Duplex communication

##Simplex communication

Simplex communication means that in the connection between the client and the server, only one party can always send messages to the other party

Half-duplex communication

Half-duplex communication means : In the same time period, only one party can send a message to the other party. Only after the message is sent, the other party can send the message. As shown below:

What is RPC communication in Node.js? What is the difference between it and Ajax?

Duplex communication

Duplex communication means that both parties can send messages to each other at any time. As shown below:

What is RPC communication in Node.js? What is the difference between it and Ajax?

The protocols are different

Ajax uses the HTTP protocol. RPC communication uses a binary protocol. The binary protocol has two main advantages over the HTTP protocol, which are:


1. Smaller data packet size (binary data instead of text data) 2. Faster encoding and decoding speed ( The computer's encoding and decoding speed for binary data is obviously higher than the encoding and decoding speed for text data!)

Conclusion

Today, we compare Ajax and The similarities and differences of RPC to understand what RPC communication is. Next time, we will further learn RPC by learning

NodejS's buffer encoding and decoding binary data. So, see you next time. study hard, improve every day!

What is RPC communication in Node.js? What is the difference between it and Ajax?

For more programming related knowledge, please visit:

Programming Video! !

The above is the detailed content of What is RPC communication in Node.js? What is the difference between it and Ajax?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete