Linux Simple Network Programming __HTML5

Source: Internet
Author: User
Tags file transfer protocol

Computer Network is a collection of computers connected by communication lines, which is a group composed of computers and peripherals, data communication and interrupt equipment. The TCP/IP protocol is the protocol used on the Internet, and the internet is the world's largest computer network. ISO has proposed an OSI reference Model for network standards, which regulates the design of computer networks and solves the problem of low-level implementations not covered by TCP/IP protocols. one of the main features of Linux systems is its powerful network capabilities. With the increasing popularity of the network, web-based applications will be more and more.
I. The composition of the computer network:
on the physical level, the computer network is composed of 3 parts, such as the machine, the network connection equipment and the transmission medium. on the logical level, the computer network is composed of 3 parts, such as Internet Protocol, network application software and data. according to the form of computer network can be divided into a variety of structures, and some of the structure applicable to a certain environment, but more of a variety of network structures combined to use the composition of the actual network. in order to standardize the communication of different computers and computer networks, the network model is used to describe the problem-solving level, and a variety of network transport protocols are developed based on the network model.
(1). Network structure
most computer networks are LANs, and the entire network is located in a building or a room. A local area network is used to share resources among multiple computers. For example, a LAN connecting two computers and a printer allows any computer to access the printer, as shown in the figure.
according to the composition form of LAN, the LAN is divided into 3 kinds of basic network structure, such as Star Network, ring network and bus network. computers are connected to a central site, the network is a star network. Star networks are like spokes of wheels, so the center of a star network is often referred to as a hub or switch. A typical hub or switch includes an electronic device that receives data from a sending computer and transmits it to a suitable destination, as shown in the figure.
The ring network connects the computer to a closed ring, one cable connects the first computer with the second computer, the other cable connects the second computer to the third, and so on, until a cable connects the last computer with the first computer, as shown in the figure.
A bus network usually has a long cable connected to the computer, and any computer connected to the bus can send signals through the bus, and all computers can receive signals. Because all computers connected to the cable can detect electronic signals, any computer can send data to other computers, as shown in the figure.
Each network structure has advantages and disadvantages. looped networks make it easy for your computer to work together and easily detect if your network is running correctly. But if two of these cables are broken, the entire ring network will fail. A star network protects the network from damage to a single cable because each cable is connected to only one machine. A bus network requires less wiring than a star network, but has the same drawbacks as a ring-like network. therefore, for a small interval, the implementation of the network may be any of these, but for large networks, is usually composed of these 3 networks of composite structures.

(2). OSI Reference Model ISO has developed an open System interconnection reference model to facilitate open interconnection of computer systems. The open interconnection feature is to support the interconnection of different system environments. The model establishes a global standard for the functional level that the open communication between computers needs to define.

the hierarchy of the model is: Physical layer: The physical layer does not mean the network hardware or transmission medium, it only exists in the abstract structure, is responsible for data flow transmission of the lowest function module. The physical layer receives the data frame from the second layer of Data Link layer (DDL) and sends the data frame serially, sending only one byte at a time. In addition, it is responsible for receiving data streams and then combining them into data frames for transmission to the data link layer. Data Link layer: The role of the data link layer is to package the data stream into a data frame, and then pass the data frame to the physical layer for delivery. Also receives the data frame from the physical layer, and through the cyclic verification to detect the data transmission reliability. Network layer: The network layer is used to establish routing between devices and to handle address information in data frames. However, the network layer does not verify the integrity of the data, but rather passes it to the data link layer. Transport Layer: The transport layer is a data processing layer which is the object of packet and network segment, it is highly abstracted data link layer service. The transport layer is responsible for the integrity of the data, and if a packet is lost, it will require the other person to resend the packet. Session Layer: The session layer is used to establish the connection between two network terminals and is very closely related to the transport layer, which determines whether the communication mode is simplex or duplex, and the basic handshake protocol. Presentation layer: The presentation layer is used to process data encoding of different computers and is responsible for the conversion of data encoding. Data coding systems for different computers may vary, such as the differences between IBM and Apple systems. Application Layer: The application tier does not include any applications, but provides interfaces for the OSI reference Model. Typically, the application layer is invoked by the network protocol by the application.

(3). TCP/IP Reference Model The OSI Reference Model is not a standard in practical application, but rather an abstract representation method. The TCP/IP Reference model is really widely used at present, and it is based on the OSI reference Model. The rapid development of the Internet makes the TCP/IP reference model used by all computers. TCP/IP protocol is a protocol set, its core is TCP protocol and IP protocol. The TCP/IP Reference model is also an open model, which can be applied to all kinds of networks such as Internet, which has the following 4 characteristics. TCP/IP is a standardized high-level protocol that provides a variety of network service protocols. The Perfect Network address assignment method, each point in the network has the independent address. non-proprietary technology, regardless of operating system and hardware structure. It is not related to network hardware and is suitable for various network structures. The TCP/IP Reference model has 4 levels. The application layer corresponds to the application layer in OSI, the transport layer corresponds to the transport layer in OSI, the network layer corresponds to the network layer in OSI, and the physical link layer corresponds to the physical layer and the data link layer in OSI. There is no presentation layer and session layer in the OSI in TCP/IP, as shown in the figure.
1). Application Layer The application tier is the highest level of the TCP/IP reference Model, and it provides users with some common applications, such as e-mail. The application layer includes all the high-level protocols, and there are always new protocols added. Application layer protocol mainly includes: Network Terminal protocol Telnet, used to realize the remote login function in the Internet; File Transfer Protocol FTP, for the realization of interactive file transfer in the Internet; Simple email protocol smtp, Internet email delivery function; Domain Name Service DNS, Network Service for implementing network device name to IP address mapping; Network File system NFS for file system sharing between different hosts in the network. 2). Transport Layer The transport layer is also called the TCP layer, and the primary function is to be responsible for end-to-end communication between application processes. The transport layer defines two protocols: TCP and User Packet protocol UDP. TCP protocol is a reliable connection-oriented protocol, the main function of which is to ensure the transmission of information error-free to the destination host. The UDP protocol is an unreliable connectionless protocol, which differs from the TCP protocol in that it does not perform packet order checking and error control, but instead gives the work to the previous application tier. 3). Network Layer The network layer, also known as the IP layer, is responsible for handling communication between computers in the Internet and providing a uniform packet to the transport layer. Its main function has the following 3 aspects: processing the packet sending request from the transport layer, processing the received packet, processing the path of the interconnect. 4). Physical link Layer The main function of the physical link layer is to receive IP packets from the IP layer, send them out through the network, or receive processing physical frames from the network, extract the IP packets and send them to the IP layer. This layer is the actual connection layer between the host and the network.
The TCP/IP protocol (transmission controlprotocol/internet Protocol) is a network protocol developed with the Internet, which is widely used at present. The internet was originally built for U.S. defense needs to ensure interoperability between the U.S. government's computer networks and to ensure that nuclear strikes are not paralysed. TCP/IP is a good solution to the health of different network accessibility and networks, leading the development of the Internet. Almost all operating systems support the TCP/IP protocol, and Linux is the most popular network server operating system in the world, as an important standard for TCP/IP protocol.
In the past 50 years, computer network technology has produced many different network structures and communication protocols, many of which are still in use today. There are two types of outcomes that allow different networks to access each other: the first is to select a group network structure as the standard so that all networks are organized in the same way. This scenario is clearly not feasible, because not only is the cost of network reconstruction too high, but there is no network structure to meet all applications.
Therefore, the second method is proposed, which requires the design of a protocol that enables all network structures to be supported. The TCP/IP protocol was born and the IP protocol was the solution to the network interoperability problem. IP protocol, also known as the Internet Protocol, corresponds to the network layer of the TCP/IP reference Model, which is the most important protocol in the Internet. The IP protocol stipulates that the packet consists of two parts, the body of the packet and the header. The packet body is the data to be passed without formatting requirements. The header includes the network address of the sending host, the network address of the receiving host, the packet header checksum, and the packet length information. The main functions of IP protocol are packet transmission, packet routing and congestion control. Packets are passed in "connectionless" mode, where the two hosts do not need to establish a connection before communicating. A unified IP packet is used between network hosts to maintain data transmission and identification between different physical networks. If the destination is a computer with the same network segment, then the packet will be transmitted directly to the past. If two hosts are in different subnets on the Internet, the IP protocol will get the transmission path between hosts through the router, passing the packets through the switch or server relay. A router is a dedicated computer that chooses a path in a network, which takes the graph algorithm as its core and is responsible for finding the shortest distance between two points. At the same time will also consider the network congestion situation, to find the actual fastest transmission path. Some of the larger data is split into packets, most likely to be delivered to destinations in different paths.
IP Internet Protocol Address
all computers on the Internet must have a unique number on the Internet as their network identity, which is called an IP address. Each packet contains the IP address of the sender and the IP address of the receiving party. The IP address is a 32-bit binary number, or 4 bytes, and is usually expressed as a w.x.y.z in the convenience of. Where, W, X, Y, z is a decimal integer of 0 to 255, corresponding to a byte in the binary notation. This representation is called dotted decimal notation. The NIP address is simply a large organization that first requests several IP addresses from the Internet's NIC (Network information Center), then assigns its down-level organization, and the subordinate organization assigns IP addresses to the next level of organization. The network administrator for each subnet assigns the IP addresses that are obtained to each computer in the subnet. The IP address is divided into 3 categories. 1. Class A address Class A IP address of the highest bit of 0, the first 8 digits of the network address, is in the application address by the Management authority set, the latter 24 for the host address, can be assigned by the network administrator to the institutions of the host subnet. The value of the first decimal integer of the Class A address is between 1 and 126. A Class A address can accommodate up to 224 (about 16 million) hosts and can have up to 127 class A addresses. Of course this is purely mathematically speaking, in fact impossible to achieve, because some of the addresses in a network have special uses, can not be assigned to specific hosts and networks. The following numbers are the same in Class B and Class C addresses. 2. Class B Address the first 16 bits of the class B IP address are the network addresses, the latter 16 are the host addresses, the first is 1, and the second digit is 0. The value of the first decimal integer of the Class B address is between 128 and 191. A Class B network can hold up to 216 or 65536 hosts, up to 214 B-class addresses. 3. Class C Address the first 24 digits of the class C IP address are network addresses, the last 8 are host addresses, and the first, second, 1, and third digits are 0. The first integer value of the class C address is between 192 and 223. A Class C network can accommodate up to 28 or 256 hosts, with a total of 221 C-class addresses. There are several special IP addresses, the first is the loopback address, which is used for network testing or native interprocess communication, in decimal form 127.0.0.1. The second is the broadcast address, which is used to call computers within the entire network, and the last address on the subnet is used as a broadcast address, such as 16.255.255.255 for calls to all computers in the Class A network 16.0.0.0. The third is the subnet address, which identifies the subnet, and the first address in the subnet is the subnet address, such as 192.168.0.0.
the original Internet uses the transmission medium for the telephone line, the computer through the modem converts the numerical signal to the analog signal, then uses the current carrier. Because the noise of the telephone line is very high, it can easily cause the bit error, so the TCP protocol has perfect cyclic checking mechanism. TCP is an important transport layer protocol and must ensure the integrity of data transmission. In addition, the packet message has computer port number information that can be used to distinguish data from different applications on the same computer. Packets are small units of data, and continuous data passed over the network is often many times the length of the packet. Therefore, there is also a sequential number in the packet packet that enables the receiving computer to restore the data sequentially, according to the number. Another important function of the TCP protocol is to cut large data into smaller packets, or to restore the packets received in order to the original data. If a packet is found to be missing, the TCP protocol sends a request to the source computer requesting that the missing packet be delivered again. This processing power is called Full-duplex. The TCP protocol has the smallest processing unit in bytes, so TCP is a byte-oriented sequential protocol. Each byte in the packet is assigned a sequential number and parity bit to verify the authenticity of the data.     Although this approach conveys too much redundant data, the root cause is caused by an extremely unreliable early network. To reliably complete the data Transfer task, TCP divides the message or data into manageable lengths, plus TCP headers, and defines some of the major fields, as shown in the figure.

The fields in the TCP message are defined as follows.     SOURCE port: The port number specified by the source computer.     Destination port: The port number of the receiving computer.     Ordinal number: The number assigned to the TCP package.     Answer number: The number that the receiving computer sends to the source computer. Offset bit: Indicates the length of the TCP header (that is, the number of 32-bit words in the TCP header). It indicates that the data begins and the TCP header ends. For a normal 20-byte header, this field is set

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.