Python Day 28 network programming, OSI seven-layer model, three-way handshake and four wave

 

  ## route network programming thinking

"" " #
 # What is network programming? 
Network usually refers to a computer in the Internet by multiple computers through a network cable or other media consisting of interlinked 

write programs based applications over a network is called network programming 

# # line of thinking: 

the aim is to link other computers in the Internet 

physical layer physical media links to other computer 

data link layer MAC address for communication, but only on the same local area 

network layer determines that a certain local area networks worldwide in the use ip a computer 

-transport layer to determine a particular port of a computer process in 

the application layer of tissue own data structures, such as JSON, XML and the like for exchanging data between two applications 

"" "

  ## C / S architecture

"" "
 # Networking requires at least two computers, and transmit data to the network using 
a network must Unicom
 2 . In one needs to access data must be installed for applications that access data in 
   the application program is called a client application ( client)

 . 3 . in one must be installed to provide data required for application sharing data of 
   the application is called the application server (server) 
       , abbreviated as C / S 
           for example: qq is a client server Tencent 
                 Tencent video 

                B / S browser browser / Server structure by this transmission data is HTML text 

# ultimate goal is to learn network programming to write an application based on C / S structure

  The basic elements of the communications network ##

# To Communication two conditions must have 
a physical transmission medium (twisted pair fiber coaxial radio waves)
 2. Communication Protocol (Key)

  ## network communication protocols

# By the sender and receiver agree on a common set of specifications 

# Why do we need agreement 
which aims to correct the two sides can resolve data 
such as internal communication: the two sides are in Mandarin 
     international communication: English 


IBM DELL HP early years of each company It has its own set of protocols which leads to different brands of computers connected to the network so the ISO can not put forward an OSI open systems interconnection model

  ## OSI seven-layer model

# #Open System Interconnection Reference Model, Open Systems Interconnection reference model for communications, abbreviated as OSI, launched by the ISO, in fact, a lot of protocols, OSI entire communication process is divided into seven layers, referred to as OSI seven-layer model 

# # right is the most complete seven-layer model, is the most complete communication model, although very detailed, but the higher complexity of the whole communication process, the latter in order to reduce the learning curve, which has been simplified, so he middle five layer, and left four 

# # wherein the application layer, presentation layer, session layer, and belong to the application layer, as a whole, so as to merge the application layer, thereby obtaining an intermediate of five, which we learn the key of!

 

 

   ## OSI works to resolve

# #OSI each layer works to resolve 
OSI is equivalent to the common language of the computer industry, just follow the provisions of OSI standards for communication, no one will be able to communicate with all computers around the world 

# function 1. Physical layer: transmission by electronic devices current signal, according to the level of current may correspond to the numbers 0 and 1, i.e. the binary data propagation media: twisted pair, cable, coaxial cable, radio wave 

# 2 data link layer 
Ethernet: 
    Ethernet protocol (Ethernet) working in the data link layer, which specifies what manner an electric signal packet, and should include a set of electrical signals 
ethernet specified as follows:
     - a set of electrical signals constitute a data packet, called 'frame'
     - each data frame is divided into: header head portion and two data data 
head 18 comprises a fixed :( bytes)

 - sender / source address, six bytes
 - the recipient / destination address, six bytes
 - data type (label + Ethertype), 6 byte 

data byte 46 comprising :( minimum, maximum 1500 bytes)

 - the packet details 

head shortest length + data length = 64 bytes, up to 1518 bytes, exceeds the maximum limit on the transmission slice 

# # MAC address : 

head Source and destination addresses contained in the address what is meant by it?

ethernet predetermined internet access devices must have the card, the address of the transmitting end and a receiving end refers to the address of the card is that the mac address 

mac address: each NIC factory are fired on a world unique mac address, length of 48 binary, generally indicated by 12 hexadecimal numbers (the first six are the vendor ID, the line number is six) 
## RADIO

 With mac address, two hosts on the same network can communicate with the

The most primitive way of using ethernet, radio communication manner, i.e. substantially by roar computer communication 

broadcast readily absorb the broadcast storm
Switch not only responsible for letting computers in the network can communicate with each other, but also to optimize network transmission

 # How to optimize it?

 When you want before pc1 and pc2 communication

 1. The need to know the MAC address of the pc2, it must first be broadcast this information to all computers,

 2. This information must be handed over to the switch, and then broadcasted by the switch,

 3.pc2 discovery message after receiving the message destination MAC own, to reply to the sender of data,

 4. must also respond to the switch, then the switch will record the MAC address corresponding to pc2 networks slogans and stored into its own cache,

 Finding a MAC address from the cache pc2 5. When hair give pc2 data,

 6. If you find pc2 sent directly to the individual, not the needed radio,

 7. If there is no previous broadcast process is repeated

 This optimization feature called auto-learning function

  ##Network layer

 

# 1.IP protocol 

IP protocol is working in the network layer protocol, full name: Internet Protocol Address, translated into Internet Protocol address 

# ### 1.1 IP address (focus)
 
- ip protocol-defined address called ip address, widely used v4 i.e. the IPv4 version, which provides the network address represented by 32-bit binary
 - 0.0.0.0-255.255.255.255 range 
- typically a ip address written as four decimal numbers, for example: 192.168.10.1 
- network number: identify the subnet
 - host number: identifies the host 

classification IP addresses: 

a category reserved for government agencies
 1.0.0.0 --- 126.0.0.0 

class B allocated to the medium-sized company
 128.0.0.0 --- 191.255.0.0 

class C is assigned to anyone in need
 192.168.0.1 - 192.168.255.254 

class D multicast for 

class E for experiments 

our computers are usually class C ip, beginning with 192.168, just because a class C anyone can use 

# 1.2 Subnet Mask (understand) 

# What is the subnet mask

The subnet mask is a 32-bit address, for shielding a part of the IP address in network identifier and host identifier distinguish and indicate that the IP address is on the LAN, or on a remote network. 

It is a part of all network, host-part 0. For example, IP addresses 172. 16.10.1, if known network is a front portion 24, the main part 8, the subnet mask is 11111111.11111111.11111111.00000000 written as a decimal is 255.255.255 .0. 

# Why do we need a subnet mask 

simple ip address only identifies the type ip address, ip which does not recognize a subnet of 
example: 192.168.10.1 and 192.168.10.2 can not determine both the same subnet, because they do not which clearly indicates the network number, which represents a host number

# 1.3 IP packet (Learn) 

ip packet is also divided into head and data portions are not required to define a single ip packet fields, directly into the data part of the Ethernet packet

head: 20 to 60-byte length

data: most a length of 65,515 bytes.

Ethernet packets and "data" section, only a maximum of 1500 bytes. Therefore, if the IP packet exceeds 1500 bytes, it will need to be split into several Ethernet data frame transmitted separately.


# 1.4 ARP protocol (understand)

the origin of the ARP protocol:? IP is usually dynamic allocation is a logical address, and data transmission must rely on MAC address, how can it get the MAC address by IP ARP which requires it the protocol

arp protocol functions: send broadcast packets, the destination hosts mac address

first clear each host ip is known and can be determined whether the same subnet by the subnet mask

** case 1: host 192
.168
.1
.101
access 192
.168
.1
.102 **

is the same subnet as
the ARP request frame contents:

1.FF: FF: FF: FF: FF: FF is a special MAC address in the switch will be seen that this address data is broadcast to all hosts within the network

After receiving the ARP request reply 2.192.168.1.102 own MAC to the source host MAC

3. sender (192.168.1.101) after receipt of reply, MAC address stored mapping relationship to each other will ip the cache for future use

ps: arp -a can view the ARP cache list

 

# Summary: ARP broadcast manner acquired by the MAC address IP address, MAC address of the other gateway when not in the same subnet ARP obtained data reach the other gateway, according to the corresponding IP host, acquired by the gateway course, the other gateway host MAC also through the ARP

ps: routers switches can be called the gateway!

 
 
 

  ## the transport layer

# The TCP / work at this level the UDP 
transport layer requires that each application bundle a port number 
port number is an integer ranging from 0 -65536 0-1024 This system is not recommended reserved 
port number can not repeat 
this point can pass ip + one port number on the application of a global positioning computer 

# TCP transmission control protocol 
    reliable transport protocol, how to guarantee reliable, after the completion of data occurs, you must wait for the recipient to return a reply message, send the data considered successful 
    if the other party does not return for some time, it will send the data again, ultra limit the number judged to be a link missing 
    transmission links based on 
    how call link 
        data to occur must first establish a link simply means that to find one to reach the other side of the road, 
        how to choose a best transmission path is controlled by the routing protocol 
    to ensure reliable data transfer chamber must ensure that the transmission path is available 
    to establish the link required three-way handshake: 
        three-way handshake is to determine the transmission is available 
        but does not guarantee reliable transmission of subsequent TCP protocol so each of the data transmission Data segments segment requires confirmation 
    broken link requires four to wave 
        to ensure that both the data transfer is complete, Why do we need one more, there may be some transmission end of the other side is not over yet
 
    benefits:
        Ensure transmission reliability, data integrity
    Cons: 
        Because of the need to confirm the transmission of information, so the network consume larger, relatively low efficiency 
    scenarios: 
        important data, online payment, text messages 


#UDP protocol User Datagram Protocol 
    unreliable transport 
    UDP just sends no matter if it was received 
    
    advantages: higher transmission efficiency than TCP 
    disadvantages: unreliable transport 
    scenarios: 
        high speed requirements, integrity requirements for lower 
        video calls, voice chat 
        war game mostly UDP you card you normally play cards right people

 

   ## three-way handshake and four waving summary


# Connection establishment TCP three-way handshake is a process, the purpose of communicating parties confirm the start numbers for subsequent 
orderly communications. The main steps are as follows:
 . 1 beginning of a connection, the connection establishment side (Client) sends a SYN packet, and includes its own initial sequence number A;.
 2 connected Recipient (Server) received SYN packet will later return a SYN packet, which comprises a. a pair of a packet 
sequence number of the ACK response information, a response desired for the next packet sequence number received, i.e., + a . 1 , and also contains 
its own initial sequence number B;
 . 3 . connection establishment side (Client) receive a return after the SYN packet, return an ACK packet in response to do, which contains the 
next desired sequence number received packet, i.e., + B . 1 .
#TCP终止连接的四次握手过程如下:
1. 首先进行关闭的一方(即发送第一个FIN)将执行主动关闭,而另一方(收到这
个FIN)执行被动关闭。
2. 当服务器收到这个FIN,它发回一个ACK,确认序号为收到的序号加1。和SYN一
样,一个FIN将占用一个序号。
3. 同时TCP服务器还向应用程序(即丢弃服务器)传送一个文件结束符。接着这个
服务器程序就关闭它的连接,导致它的TCP端发送一个FIN。
4. 客户必须发回一个确认,并将确认序号设置为收到序号加1。

   ##应用层

应用层由来:用户使用的都是应用程序,均工作于应用层,互联网是开放的,大家都可以开发自己的应用程序,用什么样的数据格式来传输,就需要由应用程序开发者自己来制定

应用层功能:规定应用程序的数据格式。

例:TCP协议可以为各种各样的程序传递数据,比如Email、WWW、FTP等等。那么,必须有不同协议规定电子邮件、网页、FTP数据的格式,这些应用程序协议就构成了”应用层”。

 

Guess you like

Origin www.cnblogs.com/liangzhenghong/p/10932762.html