Python 套接字不会阻止垃圾邮件

我正在向客户端发送消息,但客户端不会停止发送垃圾邮件


服务器.py


server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

hostname = socket.gethostname()

hostip = socket.gethostbyname(hostname)

port = 462


server.bind((hostname, port))

server.listen(1)

print((hostip, port))


client, address = server.accept()

print("New connection!: ", address)


while True:

    data = input("Do something:")

    if data == "help":

        print("test: 'test'")

        input("Click ENTER to continue")

    elif data == "test":

        client.send("test".encode('ascii'))

    else:

        continue

客户端.py


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

host = socket.gethostname()

port = 462


s.connect(('', port))

data = s.recv(1024)


while True:

    if data.decode('ascii') == "test":

        print(data.decode('ascii'))

    else:

        continue


慕码人8056858
浏览 150回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python