Software development framework
Software development framework, must develop a set of client and server
The role of client and server-side
Server: 24 hours a day to provide service
clients: If you want to find the service, look for a service and enjoy
Software development framework is divided into two types:
C / S architecture:
Client: Client
Server: server
Advantages: use of the software is stable, and can save network resources
Disadvantages: If users want to use multiple software on the same device, you must download multiple clients
2. Each software update, the client must also update download
C / S structure of the software:
For example: QQ, Pycharm like on the computer ... mobile terminal (mobile terminal) WeChat, king
B / S structure:
Browser: Browser (Client)
Server: server
Pros: to act as the client browser, without requiring the user to download multiple software, no need to download the updated version of the software user, the software used to access directly in the browser
Cons: excessive consumption of network resources, when the network is unstable, the use of the software will be unstable
B / S structure of the software:
For example: Enter the domain name a piece of software in a browser (client) ( http://xxxxxx.com/ )
network programming
- network programming development history
All counts are derived from the advanced military, hoping to get the data through remote, hence the "Network Programming"
How early remote communication: - call ---> telephone line
- flat screen computer -> Ethernet cable, wired LAN
- Laptop -> Wireless LAN
To achieve remote communication must have:
1. The physical link media ---> card ....
2. Internet Protocol
- interpersonal communication of media: Chinese, English
- communication between the computer's media: "Internet Protocol"
Internet Protocol
Internet Protocol, also known as seven-layer network protocols, OSI seven layer protocol, OSI is a world standard organization
OSI seven layer protocol:
- Application Layer
- Presentation Layer
- Session Layer
- Transport Layer
- Network Layer
- Data Link Layer
- physical connection layer
Learning from bottom to top:
Priority needs to know the total of five agreements
- physical connection layer
Based on electric signals transmitted binary data 0,101,010,111
010: you you
101: I I
- data link layer
The data link layer "Ethernet protocol", specialized user data processing based on the electrical signals transmitted binary
Ethernet protocols:
1. The provision of electrical good grouping
2. Each computer connected to the network cable must be made a "card"
- network cards from different manufacturers
- Each card will have a unique world number 12
- before 6: Vendor No.
- After six: serial number
- Switch: multiple computers may be connected together
Ethernet-based protocol to send data:
Features: Radio, thin -
Drawbacks: broadcast storm, can not communicate across local area network
- Internet: allow communication between the local area network
Network layer
IP Address: the address that uniquely identifies your computer (local area network).
IP: dotted decimal
Minimum: 0.0.0.0
Maximum: 255.255.255.255
IPV4 (to know): a few people began to use a computer, so there IPV4 protocol version
IPV6 (understand):
Native IP: loopback address, 127.0.0.1 -> localhost
Transport Layer
TCP / UDP protocol, they are based on port work
- Port Number: identifies a certain computer software
- The port number range: 0-65535
Note: 1. The operating system, ports 0-1024 are generally used by default (do not move)
The interface number after 2. Try to use 80,008,001
The default port number used in the development of software:
mysql: 3306
mongdb: 27017
Django: 8000
Tomcat: 8080
Flask: 5000
Redis: 6379
If you want the server to communicate with the client, it must establish a link, resulting in a two-way channel
A client sends a message to the server
Another one is the server to the client to send a message
Application layer
http
ftp
Summary: IP: location used to uniquely identify a computer
port: Port for a software application on the computer to confirm
ip + port: a software application on a computer world
TCP protocol works
- three-way handshake, waving four
- three-way handshake build connections:
Establish two-way channel to establish good links
listen: listen
established: confirmation request to establish a connection
- send data
write
read
The client sends data to the server, the data stored in memory, the server needs to acknowledge receipt, the data will be freed in memory
Otherwise, it will be sent once from time to time, so that the server returns a confirmation receipt
Over a period of time, if the stepless or does not return acknowledgment of receipt, the transmission is canceled, and releases the data memory
- Four waving Short link:
TIME_WITE: time to wait
Scoket
a socket module, can write a C / S architecture socket.
Socket socket protocol layers will be a good package of work
Benefits: You can save development costs
Usage: import socket
# 服务端
import socket
server = socket.socket()
server.bind(
('127.0.0.1', 9527)
)
server.listen(1)
while True:
conn, addr = server.accept()
while True:
print(addr)
try:
data = conn.recv(10).decode('utf8')
print(data)
if data == 'q':
break
conn.send(data.encode(('utf8')))
except Exception as e:
print(e)
break
conn.close()
# 客户端
import socket
client = socket.socket()
client.connect(
('127.0.0.1', 8888)
)
while True:
send_msg = input('client---》server:')
client.send(send_msg.encode('utf-8'))
if send_msg == 'q':
break
data = client.recv(1024).decode('utf-8')
print(data)
client.close()
Note: The client and server must be followed:
One end of send, the other end of the recv
different ends simultaneously send or recv