Description of Computer Network

A, c / s architecture and b / s architecture

  • c / s architecture: Client and server eg: QQ, micro-channel

    c端-----------------------网络---------------------s端

    c end: that client

    s end: a fixed IP, and it has been stable in operation, and supports high concurrency

  • b / s architecture: the browser and the server eg: Jingdong, Lynx

    In fact, the nature of b / s architecture is c / s architecture

Second, the network protocol


What is a network?

Network connection network is the Internet protocol media +

Network protocol

OSI seven layer protocol: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, application layer

Five-layer OSI protocol: physical layer, data link layer, network layer, transport layer, application layer

2.1 Physical Layer

Mainly high and low voltage electrical signal of 010101

2.2 Data Link Layer

By etherner protocol (Ethernet protocol defines a packet mode ,, Ethernet) physical layer packet to an electric signal, each set of data called a message / data frame.

  • Each data frame is divided into a header and a data head data of two parts.

| 报头(18字节) | data(46-1500) |

A header (18 bytes fixed): 6 accounted for transmitting, representing the receiver 6, data type representing 6

  • mac address: sender, receiver address, is the mac address, each card has a unique mac address, a total length of 48 binary, hexadecimal number 12 (the first six are the vendor ID, the six is ​​the number of lines)

  • Broadcasting: communication within the same LAN, there will be a broadcast storm

2.3 Network Layer

  • IP: There are IPV4 and IPV6

    IPV4: 32-bit binary, dotted decimal notation in the range 0.0.0.0 to 255.255.255.255

    IPV6: 64-bit binary

  • Subnet Mask: The IP address and subnet mask is determined whether the two IP in the same network segment, do a bitwise AND operation by the IP address and subnet mask

    IP address: 172.16.10.1:  10101100.00010000.00001010.000000001
    Subnet Mask: 255.255.255.0:  11111111.11111111.11111111.000000000
    Bitwise AND operation: 172.16.10.0 10101100.00010000.00001010.000000000

  • 172.16.10.10/24 contains the ip address and subnet mask

  • Conversion between the IP address and mac address

    Arp application protocol by sending the broadcast packet, the destination address mac address acquisition

    mac address learning: mac address mapping table and the ip address
    - the first one will be added to the received data ip / mac mapping table { '172.16.10.11 ": ddsadfgegsdgsdg}

  • By any of the data packet header and the data

2.4 Transport Layer

TCP protocol : connection-oriented, reliable

Data transmission, a response is required, the data reliability

  • Three-way handshake

  • Four waving

UDP protocol : for non-connection, unreliably

Transmitting data, no response is required, the data is not reliable

  • Port
    - by ip + subnet mask determine the only one device
    - via the subnet mask CD + ip + port number to determine a unique software
  • Semi connection pool: a substantially queue FIFO, instead of a semi-connected control connection pool, but to control the number of the intermediate connection state

2.5 Application Layer

  • Online process analysis (to access Baidu, for example): -
    Enter www.baidu.com browser
    - will take DNS servers by domain names into IP addresses
    - IP address sends a request to the port number, you will have access to Baidu's server

  • socket

    In an abstraction layer between the application layer and transport layer, it is the TCP / IP layer complex operations abstract interface to supply a few simple calling process has been implemented with a communication network layer, call socket can directly operate the transport layer and network layer

Third, demand


Write a client, the implementation is sent to the server hello wordafter a string, write a server, the client sends the data becomes capital return

#服务器
import socket   #导入模块


#SOCK_STREAM表示TCP连接,SOCK_DGRAM表示UDP连接,如果不写参数,默认TCP连接
soc = socket.socket(socket.AF_INET,socket.SOCK_STREAM)  

soc.bind(('192.168.11.195',8080)) #括号里面是一个元组 soc.listen(5) #处于监听状态,5为半连接池的大小 conn,addr = soc.accept() #等待接收数据,conn就是通路 data = conn.recv(1024) #接收数据,最多1024个字节,1024还可以是其他数字 #发送数据,数据必须是bytes格式 把客户端发来的消息处理好再发送给客户端,,upper()将数据变大写 conn.send(data.upper()) #把客户端发来的消息处理好打印出来,给自己看(客户端发来的消息 b'hello world') print('客户端发来的消息',data) conn.close() #断开连接 soc.close() #关闭连接
#客户端
import socket

soc = socket.socket()  #创建一个socket对象

soc.connect(('192.168.11.195',8080)) #连接服务端 soc.send(b'hello world') #给服务器发送数据,数据必须是bytes格式 data = soc.recv(1024) #接收数据,最大1024字节 #把客户端发来的消息处理好打印出来,给自己看(服务器发来的消息 b'HELLO WORLD') print('服务器发来的消息',data) soc.close() #关闭连接
 
  • c / s architecture: Client and server eg: QQ, micro-channel

    c端-----------------------网络---------------------s端

    c end: that client

    s end: a fixed IP, and it has been stable in operation, and supports high concurrency

  • b / s architecture: the browser and the server eg: Jingdong, Lynx

    In fact, the nature of b / s architecture is c / s architecture

Second, the network protocol


What is a network?

Network connection network is the Internet protocol media +

Network protocol

OSI seven layer protocol: physical layer, data link layer, network layer, transport layer, session layer, presentation layer, application layer

Five-layer OSI protocol: physical layer, data link layer, network layer, transport layer, application layer

2.1 Physical Layer

Mainly high and low voltage electrical signal of 010101

2.2 Data Link Layer

By etherner protocol (Ethernet protocol defines a packet mode ,, Ethernet) physical layer packet to an electric signal, each set of data called a message / data frame.

  • Each data frame is divided into a header and a data head data of two parts.

| 报头(18字节) | data(46-1500) |

​ 报头(固定18字节):发送者占6位,接收者占6位,数据类型占6位

  • mac地址 :发送者,接收者地址,就是mac地址,每个网卡都有一个唯一的mac地址,总长度为48位2进制,12位16进制数表示(前六位是厂商编号,后六位是流水线号)

  • 广播:同一个局域网内通信,会出现广播风暴

2.3 网络层

  • IP:主要有IPV4和IPV6

    IPV4:32位2进制,用点分十进制表示 范围为0.0.0.0到255.255.255.255

    IPV6:64位2进制

  • 子网掩码:通过子网掩码和IP地址判断两个IP是否处于同一个网段,通过IP地址和子网掩码做按位与运算

    IP地址: 172.16.10.1: 10101100.00010000.00001010.000000001
    子网掩码: 255.255.255.0: 11111111.11111111.11111111.000000000
    按位与运算: 172.16.10.0 10101100.00010000.00001010.000000000

  • 172.16.10.10/24 包含了ip地址和子网掩码

  • IP地址与mac地址的转换关系

    应用arp协议,通过广播发送数据包,获取目标地址的mac地址

    mac地址学习:mac地址和ip地址的映射表
    -第一次接收到就会在ip/mac映射表中添加一条数据{’172.16.10.11“:ddsadfgegsdgsdg}

  • 任何一种包都由数据头和数据组成

2.4 传输层

TCP协议:面向连接的,可靠地

发送数据,需要响应,所以数据可靠

  • 三次握手

  • 四次挥手

UDP协议:面向非连接的,不可靠地

发送数据,不需要响应,所以数据不可靠

  • 端口
    -通过ip+子网掩码确定唯一一台设备
    -通过ip+子网掩码唯+端口号确定唯一一个软件
  • 半连接池:实质上是一个队列,先进先出,半连接池不是控制连接数,而是控制连接在中间状态的连接数

2.5应用层

  • 上网流程分析(以访问百度为例):
    -在浏览器输入www.baidu.com
    -会取DNS服务器通过域名解析成IP地址
    -向IP端口号这个地址发送请求,就会访问到百度的服务器

  • socket

    ​ 在应用层和传输层之间的一个抽象层,它把TCP/IP层复杂的操作抽象为几个简单的接口供应用层调用已实现进程在网络中通信,调用socket就可以直接操作传输层和网络层

三、需求


写一个客户端,实现给服务端发送hello word字符串,写一个服务端,将客户端发送的数据变为大写后返回

#服务器
import socket   #导入模块


#SOCK_STREAM表示TCP连接,SOCK_DGRAM表示UDP连接,如果不写参数,默认TCP连接
soc = socket.socket(socket.AF_INET,socket.SOCK_STREAM)  

soc.bind(('192.168.11.195',8080)) #括号里面是一个元组 soc.listen(5) #处于监听状态,5为半连接池的大小 conn,addr = soc.accept() #等待接收数据,conn就是通路 data = conn.recv(1024) #接收数据,最多1024个字节,1024还可以是其他数字 #发送数据,数据必须是bytes格式 把客户端发来的消息处理好再发送给客户端,,upper()将数据变大写 conn.send(data.upper()) #把客户端发来的消息处理好打印出来,给自己看(客户端发来的消息 b'hello world') print('客户端发来的消息',data) conn.close() #断开连接 soc.close() #关闭连接
#客户端
import socket

soc = socket.socket()  #创建一个socket对象

soc.connect(('192.168.11.195',8080)) #连接服务端 soc.send(b'hello world') #给服务器发送数据,数据必须是bytes格式 data = soc.recv(1024) #接收数据,最大1024字节 #把客户端发来的消息处理好打印出来,给自己看(服务器发来的消息 b'HELLO WORLD') print('服务器发来的消息',data) soc.close() #关闭连接

Guess you like

Origin www.cnblogs.com/lulingjie/p/11529028.html