#以下代码是客户段代码
import socket
clinet=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
clinet.connect(("localhost",9090))
while True:
date=input("请输入你要发送给消息:")
if date is None:
break
clinet.send(date.strip().encode("utf-8"))
serv_date=clinet.recv(1024)
print(serv_date.decode("utf-8"))
#以下代码是服务起段代码
import socket
servce=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
servce.bind(("localhost",9090))
servce.listen(60)
print("开始监听客户段链接")
conn,addr=servce.accept()
print(addr)
while True:
date=conn.recv(1024)
conn.send(date)