I’m a function that lives in memory, my home is — to use your slang — the address space of the process, and my neighbor is a function that has a very interesting piece of code in it.

I often visited him, not empty-handed, but with four numbers as a gift for him to calculate, patiently waiting for him to work on the CPU for a long time, and finally, as a gift, he gave me an address where I could pick up the results.

As I visited more and more, I slowly figured out what my neighbor did: mortgage calculations.

The four parameters I sent him were the total amount of the mortgage, interest rate, loan life and repayment method (equal principal and interest is 1, equal principal is 2). What he told me was an address, which is actually a list, storing the monthly mortgage, principal and interest payable each month.

In your slang:

List calculateHouseLoan(float total, float intrestRate,  int years ,int loanType)

All calls occur in a process within the machine, which is known as a local procedure call.

This invocation is fast and can be done in the blink of an eye.

Sometimes, the mortgage calculation neighbors will exclaim: My god, what a number you sent me ah, 8 million loan total!

I knew it! Property prices in the imperial capital are rising again!

Day after day went by, and house prices rose day after day.

One morning, I went to sleep and woke up feeling a little confused, which is usually a sign that the system had been rebooted the night before.

Before I wake up, I received the boss (call my function) command, and to calculate the mortgage, I endure dizziness and hurried to find a neighbor, but this time it was replaced by a stranger, he said with a smile: “is not to find your neighbor mortgage calculation ah”

“Yes”

‘He’s moved away!

“Ah? Where did he move to? How do I calculate the mortgage?”

“He moved to another machine, I don’t know the exact location, but from the IP, it must be in the same machine.”

To be honest, this news surprised me a lot. I’ve heard people say that communicating with a machine on the network is much more difficult than communicating with a machine in the same process.

Before we lived in the same process, each function location (address) is visible to everyone, want to call, directly to the function location to execute the code.

Now this function has moved, the new address I do not know, is to know, cross-domain network call, it is said to use what socket, establish a connection, on the connection according to both sides to discuss the format, order to send data, receive data, listen to the head big, killed I also do not know.

(Code farmer turns over old Liu Note: socket story see zhang Big fat and Socket)

The stranger saw my worry and said with a smile, “Don’t worry, I am his client agent. Just give me those four parameters and I will help you deal with them.”

This guy who calls himself the client proxy knows those four arguments, maybe it works, it doesn’t seem to me that the way it’s called has changed, so I’m skeptical and I pass in the four arguments as before, and he immediately gets busy, setting up connections, sending data, receiving data, After a long time (I felt 100 times slower than usual) he said the mortgage had been calculated and the data was at the address XXXX, you go and get it.

I went to the place and, as usual, the monthly payment results were in order.

“You this mortgage calculation of the client agent really not vague ah, since you are the client agent, do you still have the server side agent?”

“Yes, I have a good gay friend in the server, I and he agreed on the format of the message, you give me the data actually I sent him through the socket, by him to call the real mortgage calculation, and then send the results back.”

Click to see a larger image

“Is this the remote procedure call (RPC) of legend?” I asked

“Yes, our two agents have done all the dirty work for you, hiding all the complicated network details from you like a local call. By the way, some people refer to me as Stub and my good gay friend as Skeleton, and I interact with him through sockets. Some RPC agents may use HTTP instead of such low-level stuff, but that’s ok, as long as the agents at both ends agree. The key is to give you a comfortable experience.”

“I had a question, what if I pass you an object in memory instead of a simple float, int?”

“Of course you have to serialize, otherwise you can’t send it over the network, float, int you have to serialize, you have to stream the values and objects in memory into binary streams so that you can send them out. My good gay friend had to deserialize the binary stream and convert it back to an object before he could call the actual function, which was a hassle.”

I expressed my deep sympathy and respect for him. It was really hard for these agents to make transparent remote calls for us.

“I heard you can also use XML and JSON?” I asked

“You know a lot! Some people, when using Http as a communication protocol, prefer to turn objects into text, such as XML/JSON, which is more readable, but you have to remember that although Http looks like text in the application layer, it has to become binary streams when it is sent out in the underlying channels, such as TCP. Turn them into text at the destination.”

(In Serialization: An old guy’s Turnaround)

After chatting for a long time, we became more and more familiar with each other. I accidentally talked about his background, and he said: “We agents, there are two main ways to be born, one is that programmers knock us out line by line of code, take pains and work hard, and the other is automatic generation.

“Automatically generated. How do I do that?”

“Taking Java as an example, you can define an interface that extends from java.rmi.Remote, write an implementation class, and then use a tool called Rmic to automatically generate proxies on both the client and server sides. Isn’t that easy?”

(note: starting with JDK5.0, even the rmic step can be omitted. The rmic step is completely generated by the JVM, and the client agent can be downloaded to the client at runtime.)

The online world is far more exciting than the single machine. I had been chatting with this agent for nearly 800 milliseconds, and my boss couldn’t wait. He complained, “What’s taking so long? Is the human debugging and putting a breakpoint on you?”

I said, “No debugging, it was a local procedure call, now it’s a remote procedure call!”

(after)

What you see is just the tip of the iceberg, more wonderful articles, please move to “code farmers turn over 2016 article essence” or “code farmers turn over the first half of 2017 article essence”

Any tips you’d like to share? Welcome to contribute! My contact information: Wechat: Liuxinlehan QQ: 3340792577

There is no shortage of job opportunities for good people, only good opportunities for themselves. But they often don’t have the energy to sift through a sea of opportunities to find the best fit.

100Offer will strictly screen talents and enterprises on the platform, so that “the best talents” and “the best companies” meet.

Scan the QR code below to register 100Offer and talk about your expectations for your next job. Within a week, you’ll receive 5-10 great opportunities to meet your needs!