服务端
import socket
phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)#(基于网络通信,TCP协议)
phone.bind(('127.0.0.1',8000))#绑定电话卡
phone.listen(5)# 最多几个等电话,开机
print('listen')
con,addr=phone.accept()#电话链接,对方手机号,等电话
print('accept')
msn=con.recv(1024)#收多少字节信息,收消息,拨通
print('客户端发来的消息是:',msg)#发消息
con.send(msg.upper())
con.close()
phone.close()
客户端
import socket
phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
phone.connect('127.0.0.1',8000#拨通电话
phone.send('hello'.encode(utf-8))
data=phone.recv(1024)
print('收到服务端发来的消息:',data)