套接字通信底层原理
由应用程序内存拷贝到操作系统,操作系统遵循TCP协议向对方去发,对方接收到并发送信号
from socket import * client = socket(AF_INET, SOCK_STREAM) client.connect(('127.0.0.1', 8081)) # 通信循环 while True: msg=input('>>: ').strip() #msg='' if len(msg) == 0:continue client.send(msg.encode('utf-8')) #client.send(b'') print('has send') data=client.recv(1024) print('has recv') print(data) client.close()