The main contents of this section are as follows:
1. Customer Short Server Architecture
2. Network communication process
3. Initial knowledge of socket
I. Client Server Architecture
ClientServer Architecture:
Software C S Architecture: Client Server Architecture: Jingdong, Taobao, Today's Headlines, qq, Wechat...
B S Architecture: Browser Server > Unified Interface
Hardware CS Architecture: Printer.
2. Network communication process
Network Line: Transmission of Electrical Signals
Hub: Connect all network devices connected to the hub
Switch: Upgraded Hub
Network Card: Provide Network Interface, Receive Electric Signal
MAC address: Physical address, 48-bit binary length, usually represented by 12-bit hexadecimal number (the first six are manufacturer numbers, the last six are pipeline numbers)
How to view the mac address: Enter the ipconfig-all instruction in the cmd window under windows: The physical address shown below is the mac address.
IP Address: It consists of four decimal digits, each of which corresponds to eight binary digits.
about Network Communications Please click on the link to view the whole process.
3. Initial knowledge of socket
socket is a tool for network programming. Here are two simple pieces of code.
import socket #Create a socket object server = socket.socket() #It's equivalent to creating a phone. ip_port = ('192.168.111.1',8001) #Create a phone card server.bind(ip_port) #Plug in the phone card server.listen(5) #Listen to the phone, I can listen to five, after receiving a phone call, there are four people to call me.
But the last four people have to wait in line, waiting for my first phone to hang up, and the sixth person's cell phone will report a mistake when it comes to the sixth one. print('11111') #Waiting for someone to call me, when they call, I get this connection to each other. conn The phone number of the opposite party addr conn,addr = server.accept() #Block up,Wait until someone connects me, and then they get a Yuanzu, which is a connecting channel. conn Address of the other party(ip+port) print('22222') print(conn) print('>>>>>>>>>',addr) while True: from_client_data = conn.recv(1024) #The server must receive messages through a connection between the two. from_client_data = from_client_data.decode('utf-8') print(from_client_data) if from_client_data == 'bye': break server_input = input('Mingwei said>>>>: ') conn.send(server_input.encode('utf-8')) if server_input == 'bye': break conn.close() #Hang up the phone server.close() #Cell phone
import socket import time client = socket.socket() server_ip_port = ('192.168.111.1',8001) client.connect(server_ip_port) while True: client_input = input('Xiaowen said>>>>: ') client.send(client_input.encode('utf-8')) #Send a message to the server if client_input == 'bye': break from_server_data = client.recv(1024) print('Messages from the server:',from_server_data.decode('utf-8')) if from_server_data.decode('utf-8') == 'bye': break client.close() #Client hangs up