Network Programming Protocol

1. Client / Server Architecture

      

Second, osi seven layers  

Introduction:

  It should be noted that a complete computer system is composed of hardware, operating system, and application software. With these three conditions, a computer system can play with itself.

  If you want to play with others, then you need to go online. What is the Internet?

  The core of the Internet is composed of a bunch of protocols, and the protocol is the standard. For example, the standard of communication for people all over the world is English

  If you compare a computer to a person, the Internet protocol is the English of the computer world. All computers have learned the Internet protocol, then all computers can be unified

  Standard to send and receive information to complete the communication.

  People logically divide Internet protocols into layers according to their division of labor

          

 

  Internet protocol is divided into seven layers of osi or five layers of tcp / ip or four layers of tcp / ip according to different functions

Three, tcp / ip five-layer model

  The first physical layer: mainly send high and low voltages (electrical signals) based on electrical characteristics, high voltage corresponds to number 1, low voltage corresponds to number 0

  Second floor:

    The origin of the data link layer: pure electrical signals 0 and 1 have no meaning, you must specify how many bits of the electrical signal, and what each group means

    The function of the data link layer: defines the grouping of electrical signals  

    Ethernet protocol: ethernet

    •   A set of electrical signals form a data packet, called a "frame"

    •   Each data frame is divided into two parts: header and data

    •   head contains: (fixed 18 bytes)

      • Sender / source address, 6 bytes

      • Receiver / target address, 6 bytes

      • Data type, 6 bytes

        data contains: (minimum 46 bytes, maximum 1500 bytes)

      • The specific content of the data packet

      head length + data length = the shortest 64 bytes, the longest 1518 bytes, if it exceeds the maximum limit, send it in fragments

    

 

  mac address:

    The source and destination addresses contained in the head are derived from: ethernet stipulates that all devices connected to the Internet must have a network card, and the addresses of the sending end and the receiving end refer to the address of the network card, that is, the mac address

    mac address: Each network card is burned to the world's only mac address when it leaves the factory. The length is 48 digits in binary, usually represented by 12 digits in hexadecimal (the first six digits are the manufacturer's number, the last six digits are the pipeline number)

                   

 

 

  broadcast:

    With the mac address, two hosts in the same network can communicate (one host obtains the mac address of another host through the arp protocol)

    Ethernet uses the most primitive way, broadcast to communicate, that is, computer communication basically depends on roar

                 

Layer 3: Network layer

  With ethernet, mac address, and broadcast sending methods, computers in the world can communicate with each other. The problem is that the world-wide Internet is a small local area network that is isolated from each other.

  Composed, then if all communications are broadcast using Ethernet, then the packets sent by one machine will be received all over the world. This is not just a problem of inefficiency, it will be a disaster

              

 

  The conclusion of the above figure: You must find a way to distinguish which computers belong to the same broadcast domain and which are not. If they are, they are sent by broadcast. If they are not,

  The routing method (distribution of data packets to different broadcast domains / subnets), the mac address cannot be distinguished, it is only related to the manufacturer

  Network layer function: introduce a new set of addresses to distinguish different broadcast domains / subnets, this set of addresses is the network address

IP protocol:

  • The protocol that specifies the network address is called the ip protocol. The address it defines is called the ip address. The widely used version of v4 is ipv4. It specifies that the network address is represented by 32-bit binary

  • Range 0.0.0.0-255.255.255.255

  • An IP address is usually written as a four-segment decimal number, for example: 172.16.10.1

 The ip address is divided into two parts

  • Network part: Identify the subnet

  • Host part: Identify the host

  Note: The pure IP address segment only identifies the type of IP address, and the subnet where an IP is located cannot be identified from the network part or the host part

  Example: 172.16.10.1 and 172.16.10.2 are not sure they are on the same subnet

Subnet mask

  The so-called "subnet mask" is a parameter that indicates the characteristics of the subnet. It is equivalent to an IP address in form, and is also a 32-bit binary number, and its network part is all 1,

  The host part is all 0, if the network part is known to be the first 24 bits, the host part is the last 8 bits, then the subnet mask is 11111111.11111111.11111111.00000000,

  Written in decimal is 255.255.255.0.

  Knowing the "subnet mask", we can determine whether any two IP addresses are on the same subnet. The method is to AND the two IP addresses and the subnet mask separately (two

  The digits are all 1, the operation result is 1, otherwise it is 0), and then compare the results are the same, if it is, it means that they are in the same subnet, otherwise it is not.

  To sum up, there are two main roles of the IP protocol, one is to assign an IP address to each computer, and the other is to determine which addresses are on the same subnet.

 ip packet

  The ip data packet is also divided into head and data parts. There is no need to define a separate field for the ip packet. Put it directly into the data part of the Ethernet packet 

   head: length is 20 to 60 bytes

  data: Maximum length is 65,515 bytes.

  The "data" part of an Ethernet packet is only 1500 bytes long. Therefore, if the IP packet exceeds 1500 bytes, it needs to be split into several Ethernet packets and sent separately.

arp protocol

  The origin of the arp protocol: computer communication basically depends on the roar, that is, the broadcast method, all upper-layer packets must be encapsulated with an Ethernet header at the end, and then sent through the Ethernet protocol. When talking about the Ethernet protocol

  We understand that communication is implemented based on the broadcast method of mac. When a computer sends a packet, it is easy to obtain its own mac. How to obtain the mac of the target host requires the arp protocol.

  arp protocol function: send packets in broadcast mode to get the mac address of the target host

   Protocol working mode: each host IP is known

      

 

 Layer 4: Transport layer

  The origin of the transport layer: the IP of the network layer helps us to partition the molecular network, the mac of the Ethernet layer helps us find the host, and then everyone uses applications, and qq may be opened on your computer at the same time.

  Storm video, waiting for multiple applications, then we found a specific host through ip and mac, how to identify the application on this host, the answer is the port, the port is the application and

  The number associated with the network card.

  Transport layer function: establish port-to-port communication

  Supplement: Port range 0-65535, 0-1023 is occupied by the system

  tcp protocol

    Reliable transmission, TCP data packets have no length limit, in theory can be infinitely long, but in order to ensure the efficiency of the network, usually the length of TCP data packets will not exceed the length of IP data packets to ensure that a single TCP data packet does not need to be divided.

                        

  udp protocol

    Unreliable transmission, the "header" part only has a total of 8 bytes, the total length does not exceed 65,535 bytes, just put into an IP data packet.

                              

 

tcp handshake three times and wave four times

                

 

 

The origin of the application layer: users use applications, all work in the application layer, the Internet is developed, everyone can develop their own applications, the data is diverse and must be specified

  Organizational form of data Application layer function: Specifies the data format of the application.

 

  Example: TCP protocol can transfer data for various programs, such as Email, WWW, FTP, etc. Then, there must be different agreements stipulating the format of emails, web pages, FTP data,

  These application protocols constitute the "application layer".

                                       

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/qjk95/p/12714251.html