tailieunhanh - Foundations of Python Network Programming 2nd edition phần 10
Remote Procedure Call (RPC) hệ thống cho phép bạn gọi một chức năng từ xa bằng cách sử dụng cú pháp tương tự mà bạn sẽ sử dụng khi gọi một thói quen trong một API hoặc thư viện địa phương. Điều này có xu hướng thể hữu ích trong hai tình huống: • Chương trình của bạn có rất nhiều việc phải làm, | C H A P T E R 18 RPC Remote Procedure Call RPC systems let you call a remote function using the same syntax that you would use when calling a routine in a local API or library. This tends to be useful in two situations Your program has a lot of work to do and you want to spread it across several machines by making calls across the network. You need data or information that is only available on another hard drive or network and an RPC interface lets you easily send queries to another system to get back an answer. The first remote procedure systems tended to be written for low-level languages like C and therefore placed bytes on the network that looked very much like the bytes already being written on to the processor stack every time one C function called another. And just as a C program could not safely call a library function without a header file that told it exactly how to lay out the function s arguments in memory any errors often resulted in a crash RPC calls could not be made without knowing ahead of time how the data would be serialized. Each RPC payload in fact looked exactly like a block of binary data that has been formatted by the Python struct module that we looked at in Chapter 5. But today our machines and networks are fast enough that we are often in the mood to exchange some memory and speed for protocols that are more robust and that require less coordination between two pieces of code that are in conversation. Older RPC protocols would have sent a stream of bytes like the following 0 0 0 1 64 36 0 0 0 0 0 0 It would have been up to the receiver to know that the function s parameters are a 32-bit integer and a 64-bit floating point number and then to decode the twelve bytes to the integer 1 and the number . But these days the payload is likely to be XML written in a way that makes it all but impossible to interpret the arguments as anything other than an integer and a floating-point number params param value i4 41 i4 value param param value .
đang nạp các trang xem trước