table of Contents
- day31 Homework
- 1. Class 5 talk network protocol layer model, the contents of each sort out
- 2. The three-way handshake described drawing, four wave, and c are end and side state s
- 3. Write a client to achieve the string hello world send to the server, write a server, the client sends the data into a capital return
- blog address
day31 Homework
1. Class 5 talk network protocol layer model, the contents of each sort out
Physical Layer
Physical layer functions: main transmitting low voltage (electric signal) based on the electrical characteristics, a high voltage corresponding to the number 1, a low voltage corresponding to the digital 0. Network data is transmitted through the electrical signals consisting 01010101100101 format.
data link layer
The electrical physical layer packet, a set of electrical signals constitute a data packet, called 'frames', each data frame is divided into: a header and a data head data of two parts.
- fixing head comprising :( 18 bytes)
- Sender / source address of 6 bytes
- Recipient / destination address, six bytes
- Data type, six bytes
- 46 byte data comprising :( minimum, maximum 1500 bytes)
mac address: datagram sender address and the recipient address is mac address. Each one has a unique network card mac address: 12 hexadecimal number (first 6 digits is the vendor ID, the line number is 6)
Broadcasting: communication within the same LAN, thanks to roar, to send data to a computer local area network, you need to send a request to all the computers, and then we have to get that computer to receive data. (Bulk)
Network layer
- ip: ipv4: 32-bit binary represented: dotted decimal notation from 0.0.0.0 to 255.255.255.255, the range is limited, not shown all the network devices, so there ipv6
- Subnet Mask: subnet mask and ip is determined by two ip is in the same network segment, do a bitwise ip address and subnet mask by
- ip have a relationship with mac converter
- Host 172.16.10.10/24 access 172.16.10.11/24
- ARP protocol: send a broadcast packet, the destination hosts mac address
- mac address learning: mac address and ip address mapping table
- The first one will be added to the received data ip / mac mapping table { '172.16.10.1': 'localhost'}
- Any kind of protocol has headers and content
- Host 172.16.10.10/24 access 172.16.10.11/24
Transport Layer
- tcp protocol:
- Three-way handshake, four wave (focus, Figure), how the connection is established, how to send data to ensure reliable, disconnect how to disconnect, there is a state in the process of establishing a connection
- If you see a large number of state services syn_rcvd
- dos and ddos attacks: denial of service attacks, distributed denial of service attack
- Port number: port range 0-65535,0-1023 port is occupied by the system
- udp protocol:
- Transmitting, to not require a response, not on the data, (see video)
- port
- Ip + subnet mask uniquely determined by a device
- Subnet mask by ip + CD + port number uniquely identifies a software
- Semijoin pool
Application layer
The origin of the application layer: the user is using the application, are working at the application layer, is the development of the Internet, everyone can develop their own applications, a variety of data, data must be provided in the form of good organization
Application layer functions: a predetermined data format of the application.
- Example: TCP protocol data can be transferred to various programs, such as Email, WWW, FTP and the like. So, there must be agreement provides different e-mail, Web pages, FTP data format, these application protocols constitute the "application level."
2. The three-way handshake described drawing, four wave, and c are end and side state s
Three-way handshake:
- The client sends a connection request to the server.
- Responses Agree server the client's request and sends a connection request from a client.
- Client server response, agreed to connect.
Four wave:
- The client sends a disconnection request to the server.
- Agreed to request the server to respond to client disconnected.
- The server sends a request to disconnect customers.
- The client agreed to respond to service requests end disconnected.
3. Write a client to achieve the string hello world send to the server, write a server, the client sends the data into a capital return
Server code:
import socket
soc = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
soc.bind(('127.0.0.1',8081))
soc.listen(5)
conn,addr = soc.accept()
print(addr)
data = conn.recv(1024)
conn.send(data.upper())
conn.close()
Client code:
import socket
soc = socket.socket()
soc.connect(('127.0.0.1',8081))
soc.send(b'hello world')
data = soc.recv(1024)
print(f'我收到了服务端回的消息:{data.decode("utf8")}')
soc.close()
operation result:
I received a message back to the server: HELLO WORLD