Import Socket # Socket employed cs structure, Client and Server B / S and Browser Server our sock = socket.socket (socket.AF_INET, socket.SOCK_STREAM) # Family Group # socket.AF_INET IP # socket.AF_INET6 IPv6 # socket.AF_UNIX UNIX systems data transmission protocol used between the # of the type type # socket.SOCK_STREAM TCP # socket.SOCK_DGRAM UDP # passive blocking receiver # passively, not actively initiate communication, just waiting for the communication request # obstruction, when initiating the communication, the communication was only completed once next enter a # communicate three types # simplex communication is only one channel, the identity of communicating parties irreversible BB machine # half-duplex communication is only one channel, the identity of communicating parties reversible walkie-talkie #Only a number of full-duplex communication channel, the identity of communicating parties reversible phone sock.bind (( "" , 8000 )) # dual-element tuple # elements First, ip if empty, binding all current ip # element Second port, 0-65535 port, typically before the system reserved port 1000 # 3306 MySQL # 22 is SSH # 80 HTTP # 224 HTTPS # 8000 dog cool music sock.listen (. 5) # monitor # queue length con, add = sock.accept () # receiving # CON a new socket object # the Add identity of the client ip and port the while True: Content = con.recv (512 ) # single maximum length is 512 bytes received print(content.decode()) send_data = input(">>>").encode() con.send(send_data) sock.close()
#coding:utf-8 import socket sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect(("10.10.21.131",8000)) # sock.connect(("10.10.21.131",8000)) while True: send_data = input(">>>").encode() sock.send(send_data) content = sock.recv(512) print(content.decode()) sock.close()