server端
import socket sk = socket.socket() address = ('127.0.0.1',8000) sk.bind(address) sk.listen(3) #这里的3是指允许等待连接的数量 print('waitting......') conn,addr = sk.accept() input01 = input('发送>>>') conn.send(bytes(input01,'utf-8')) data1=conn.recv(1024) print(str(data1,'utf-8'))
client端
import socket sk = socket.socket() #建立tcp连接 address = ('127.0.0.1',8000) sk.connect(address) data=sk.recv(1024) #1024为最大接收数据量,k print(str(data,'utf-8')) data1=sk.send(bytes('一二三','utf-8'))