Linux Network Programming Reading Notes (8)

xiaoxiao2021-03-06  43

Chapter 11 Transmission and XDR Standards for Data Structure

· 11.1 Transmission of data structure

Network data structures may have the following problems: network box issues, floating point digital transmission, pointer processing

Custom manual processing method:

The transmission buffer to be sent after the data structure is transmitted.

The data structure is converted after the data structure conversion in the application buffer.

Code example:

Void send_int32_2buf (char * buf, unit32_t n)

{

n = htonl (n);

Bcopy ((char *) & n, buf, sizeof (unit32_t));

}

Void send_string_2buf (char * buf, char * STR);

{

Bcopy (STR, BUF, STRLEN (STR);

}

Void send2_buf (char * buf, struct u_data * ptr)

{

Send_int32_2buf (buf, ptr-> aint);

BUF = SizeOf (Unit32_t);

Send_string_2buf (buf, ptr-> str);

BUF = Strlen (PTR-> STR); // * Sizeof (char)

}

Void Recv_INT32_FROM (Char * BUF, Unit32_t * n)

{

BCOPY (BUF, (Void *) n, sizeof (unit32_t));

* n = ntohl (* n);

}

Void Recv_From_BUF (Char * BUF, Struct U_Data * PTR)

{

RECV_INT32_FROM_BUF (BUF, & (Ptr-> AINT));

BUF = SIZEOF (uint32_t);

}

· XDR standard and realization principle

The XDR data structure transmission standard is Sun design, has become the fact that most client / server applications.

XDR specifies the encoding method for various data types. The initialization function is

#include

EXTERN VOID XDRMEM_CREATE ((xdr * xdrs, const Caddr_t addr, u_int size, enum xdr_op xop); // xdRS is created XDR stream pointer, addr is a storage buffer to store XDR stream

XDR's stream conversion mode is similar to the above-defined manner, but the processing of various data types has been unified. The application design and pairing receives and transmits each data item separately.

XDR has two types of memory flow and I / O flow. The memory flow can be used, and the data structure transmission between the socket buffer interval is performed; the result of the codec will be output to the file stream using the I / O stream.

XDR and TCP are abstraction of streams, so both can be well combined. In addition, XDR provides recorded XDR abstraction, which is used in UDP transmission.

The operation of the XDR conversion function is determined in the nature of the XDR stream itself. If the XDR is the encoded stream, the conversion function is done data encoding. If it is a decoded stream, the conversion function is done data decoding.

Chapter 12 RPC Remote Process Calling Principle and Implementation

· RPC principle

Using the XDR protocol allows data structures to be transmitted in network transmission, using RPC (Remote Procedure Call) remote procedure to make functions run on different hosts. The purpose of RPC to achieve is to separate network communication functions and applications.

The center of RPC is a priority analysis analysis, separating it after the module function is divided. These modules are running on different hosts, and the RPC ensures that the semantics before and after the module is separated.

Four principles of function calls:

1 Prepare the required parameters required, allows the call to access to the modified function.

2 must contain the return information of the function

3 can determine where the call function is called

4 Creating a running environment for calling functions

The "local call" is an implementation of the above four principles. transfer:

We can save calling procedure parameters using defined information formats, explaining how to find called by the caller in the information format (usually some sign). Then send information packets to the machine to be called through the network, and then the caller is waiting to be sent back by the caller. [Conditions 1 and 3]

There should be a dispatcher to control all remote call procedures on the host. After receiving the message, the flag is received, know which one needs to call, remove the parameters required by the caller and then incorporated. [Condition 2]

The called process runs in its environment and writes the running result in the information format, and the last network returns the result of the call. [Condition 4]

· RPC implementation

Remote process marking: (program number, remote call process version number, remote process serial number)

Dynamic mapping of ports: Each remote call process corresponds to a transport layer port with an operating system dynamically assigned. The caller needs to call a remote call process, which sends a request to the port mapper, then the port mapr returns the port number of the corresponding remote call process by checking the table. Then it initiates a call request to the remote call process.

RPC packet: RPC uses packets for the application using the XDR language.

RPC Development Tools: Since the ONC RPC protocol procedure is very complicated, the system provides tools for developing RPCs. Note: XDR library functions, RPC runtime library functions, automatic generating tools for some programs, generating a C program file required by a component RPC distributed program, which is mainly impact on the application of the underlying communication.

The client is mainly implemented:

Send a request to the port mapper and receive a response from the port mapper; forming a Call message, send a call request to the real remote call process to receive the call results from the server.

The server segment is mainly implemented:

Register your own actual port to the port map before providing a service; assisted a call to a call process in the specific call program.

· RPC implementation

Remote process marking: (program number, remote call process version number, remote process serial number)

Dynamic mapping of ports: Each remote call process corresponds to a transport layer port with an operating system dynamically assigned. The caller needs to call a remote call process, which sends a request to the port mapper, then the port mapr returns the port number of the corresponding remote call process by checking the table. Then it initiates a call request to the remote call process.

RPC packet: RPC uses packets for the application using the XDR language.

RPC Development Tools: Since the ONC RPC protocol procedure is very complicated, the system provides tools for developing RPCs. Note: XDR library functions, RPC runtime library functions, automatic generating tools for some programs, generating a C program file required by a component RPC distributed program, which is mainly impact on the application of the underlying communication.

The client is mainly implemented:

Send a request to the port mapper and receive a response from the port mapper; forming a Call message, send a call request to the real remote call process to receive the call results from the server.

The server segment is mainly implemented:

Register your own actual port to the port map before providing a service; assisted a call to a call process in the specific call program.

转载请注明原文地址:https://www.9cbs.com/read-57291.html

New Post(0)