import socket
import time
while 1:
print(“请输入你要发送的内容:(***退出)\n”)
content = str(input())
print(“你输入的内容是:%s\n” % content)
if (content == “***”):
break
sk = socket.socket()
sk.connect((“xxx”, xxx)) # 绑定ip port
sk.settimeout(60)
sk.send(bytes(content.encode(“utf-8”)))
ret = sk.recv(1024)
print(“对方已收到\n”)
print(ret.decode(“utf-8”))
print("\n")
服务端的ip填私网ip 客户端填公网ip
端口设置时要去阿里云控制台开通端口 并绑定客户端的ip(客户端的ip也可以不做限制)