Linux under C Programming: The communication mechanism and architecture model of network programming

Source: Internet
Author: User
Tags data structures error handling linux

When it comes to Linux operating systems, you cannot fail to mention network technology. The Linux system itself is a network of products, it can be on the network for people to download freely, and be modified and perfected. The Linux system supports a variety of network protocols, and its shell provides powerful networking commands. These advantages enable Linux to provide a complete solution for many small and medium sized network applications.

Referring to the computer network, we have to first introduce its communication mechanism and architecture model.

1. Communication mode

The implementation of all network communication can be divided into two types: line switching and packet switching.

The so-called line exchange, refers to the transmission between the sender and the receiver to establish a specific line connection, the data can be transmitted on this line. The most commonly used telephone is the technology of this circuit exchange. But the computer network uses the method of packet exchange. All computers use a common network connection, the data sent by the sender of the data will be transferred into chunks, and each block after the appropriate processing (data encapsulation) to form a packet, the packet has the address of the receiving end, and other necessary information, and each packet transmission alone. The data in the package is not limited to death, and as long as the data is correctly transmitted, what information should be defined is relevant to the protocol used.

2. OSI Standard

The OSI standard is the Open Systems Interconnection standard (open System interconnection), which is a reference model proposed by the International Organization for Standardization (ISO) in 1977. It defines a seven-layer communication protocol standard. Specific layered structures and functions are as follows (from high to low):

(1) Application layer

The application layer is the highest level of the network, the one that is closest to the user. The application layer contains the network application software built on various communication protocols, which can realize the function of direct interaction with the user. such as e-mail and file transfer programs.

(2) Presentation layer

The presentation layer completes the representation and interpretation of the transmitted data, which includes data conversion and data encryption as well as data compression. Its main functions are: to provide users with the means to execute session-level service primitives, to provide methods to describe complex data structures, to manage the current data structure set, and to transform the internal and external formats of the data.

(3) Session Layer

The session layer uses the reliable End-to-end Communication service provided by the Transport layer protocol and increases the additional functionality required by some users and establishes data exchange between users on different machines.

(4) Transport layer

It is the core of the OSI network architecture, separating the actual communication subnet from the high-level applications, providing high reliability and low-cost data transfer between the sender and receiver. Both TCP and UDP protocols belong to this layer.

(5) Network layer

The network layer mainly defines the interaction between the host and the network, which is also called the communication subnet layer, defines the basic data unit and the concept of destination addressing and routing in the Network. IP protocols belong to this layer.

(6) Data Link layer

The data link layer packages the data from the lower level and divides the upper data into frames, which also completes the flow control and error handling work.

(7) Physical layer

The physical layer is the lowest level of OSI, which prescribes the transmission media itself and its associated mechanical and electrical interfaces. These interfaces and transmission media must ensure consistency between sending and receiving signals.

TCP/IP protocol

The TCP/IP protocol is a group of protocols that provide reliable data transfer and no-connection information services in the network. The protocol that provides reliable data transfer is known as Transmission Control Protocol TCP, while the protocol providing connectionless packet services is called Internet Protocol IP. But the TCP/IP protocol is not just TCP and IP two protocols, but a collection of network protocols that contain many other protocols.

The TCP/IP protocol began operating on the ARPA network in 1983 and was inserted into the Bsdunix operating system's kernel as part of the operating system. The TCP/IP protocol then became popular with UNIX operating systems, becoming the most widely used protocol. The main services provided by networks using the TCP/IP protocol are: E-mail, file transfer, remote logins, network file systems, videoconferencing systems, and Mwsaic and the World Wide Web.

The TCP/IP protocol architecture consists of four layers (from high to low):

(1) Application layer

The application layer includes the network application and the network process, is interacts with the user the interface, it provides the various services which the user needs, including the remote login, the file transmission and the electronic mail and so on. It acts as the application layer and presentation layer and session layer in OSI.

(2) Transport layer

Equivalent to the transport layer in OSI, which provides communication services to the application, which is called end-to-end communication. It has three major protocols: Transmission Control Protocol (TCP), User Packet Protocol (UDP), and Internet Controlled Message Protocol (ICMP).

The TCP protocol, which aims to establish a high reliability connection for message transmission, is responsible for sending a large number of user data into multiple packets at a certain length, and then reorganizing and recovering user data in the order of decomposition after receiving the packet. It is a reliable two-way communication-oriented data stream for connection.

The UDP protocol provides connectionless packet transport services, which decompose user data into multiple packets and send them to the receiver. It has the advantages of small execution code, small system overhead, and fast processing speed.

ICMP protocol is mainly used for terminal host and gateway and Internet Management Center, such as message communication, in order to control the operation of the network management purposes. The ICMP protocol can send an error message to the end host that sends the packet, as well as the ability to limit traffic.

(3) Network layer

Equivalent to the OSI Network layer, the protocol used is the IP protocol. It is used to handle communication problems between machines, it receives transport layer requests and transmits a packet with destination address information. This layer encapsulates the packet into the IP packet, fills in the header of the packet, uses the routing algorithm to choose whether to send the packet directly to the target host or to the router, and then gives the packet to the corresponding network interface module in the network interface layer below.

(4) Network interface layer

Equivalent to the data link layer and the physical layer in OSI. It is responsible for receiving IP packets and sending packets through the selected network.

View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.