34-Network Programming

Network communication

The significance of the existence of the network is the cross-regional data transmission = "It is called the communication
network = physical link medium + Internet communication protocol

CS architecture and BS architecture

  CS architecture

  Client<===========>Server

  Client software send Server software Recv
  operating system Operating system
  Computer hardware <==== Physical medium =====> Computer hardware

 BS architecture

  Browser<===========>Server

 

Two OSI Layer 7 protocol

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

 

 

Five-layer protocol
Application layer
Transport layer
Network layer
Data link layer
Physical layer

Agreement: specify the format of data organization
Format: header + data part

The process of closing the package : data plus the head
The process of unpacking: removing the head to get the data

OSI seven-layer protocol data transmission package and unpacking process

 Layer 3 and 5

Computer 1: Computer 2:

Application layer Application layer
Transport layer Transport layer
Network layer Network layer
Data link layer Data link layer
Physical layer <=========== Interactive machine ===========> Physical layer
0101010101010

(Source mac address, target mac address) (source ip address, target ip address) data

3.1 The physical layer is responsible for sending electrical signals

A set of physical layer data is called: a
simple electrical signal is meaningless and must be grouped

3.2 Data link layer: ethernet Ethernet protocol

Rule 1: A set of data is called a data frame
Rule 2: The data frame is divided into two parts = "Header + Data
Header contains: source address and destination address, the address is mac address
Data contains: contains is sent from the network layer Overall content

Rule 3: It is stipulated that all hosts connected to the Internet must have a network card, and each network card is burned with a unique address in the world at the factory.

Note: Computer communication basically depends on the roar, that is, the working mode of the Ethernet protocol is broadcast

 

(Source MAC address, destination MAC address, type) (data content) (FCS)  

The type determines what protocol is used in the network layer, FCS is used for error checking

 

3.3 Network layer: IP protocol

3.3.1 Divide the broadcast domain

In every broadcast domain, if you want to connect to the outside, there must be a gateway to help the internal computer forward the packet to the public network
gateway and communicate with the outside world by routing protocol  (RIP, OSPF internal gateway protocol BGP external gateway protocol)

 

3.3.2 IP data packets

Rule 1: A group of data is called a data packet


Rule 2: The data frame is divided into two parts = "header + data

The header contains: the source address and the destination address, which is an IP address. The
data contains: the overall content sent from the transport layer

 

3.3.3 Subnetting

ipv4 address:
8bit.8bit.8bit.8bit

0.0.0.0
255.255.255.255

Subnet mask:
8bit.8bit.8bit.8bit

255.255.255.0 corresponding binary expression
11111111.11111111.11111111.00000000

A valid IPv4 address component = ip address / subnet mask address
172.16.10.1/255.255.255.0
172.16.10.1/24

计算机1:
172.16.10.1:     10101100.00010000.00001010.000000001
255255.255.255.0: 11111111.11111111.11111111.000000000
172.16.10.0:      10101100.00010000.00001010.000000000


计算机2:
172.16.10.2:      10101100.00010000.00001010.000000010
255.255.255.255.0: 11111111.11111111.11111111.000000000
172.16.10.0:       10101100.00010000.00001010.000000000

计算机1: 计算机2:

应用层 应用层
传输层 传输层
网络层 网络层
数据链路层 数据链路层
物理层 <=========二层交互机========> 物理层
0101010101010

(源mac地址,xxxx)(源ip地址,目标ip地址)数据
(源mac地址,网关的mac地址)(172.16.10.10/24,101.100.200.11/10)数据

 

事先知道的是对方的ip地址
但是计算机的底层通信是基于ethernet以太网协议的mac地址通信

 

ARP:
若目标IP地址与源IP地址在同一网段,则直接广播问目标IP地址的MAC地址。仅第一次需要解析,后多存于缓存。

若不在同一网段,则向网关发送,由网关向外转发。

 

Guess you like

Origin www.cnblogs.com/zhubincheng/p/12716829.html