from socket import socket, AF_INET, SOCK_STREAM
sock = socket(AF_INET, SOCK_STREAM)
sock.bind(("localhost", 7777))
sock.listen(1)
while True:
try:
connection, address = sock.accept()
print("connected from " + address)
received_message = sock.recv(300)
if not received_message:
break
connection.sendall(b"hello")
except KeyBoardInterrupt:
connection.close()
我正在努力理解套接字并编写了这个相当简单的脚本,但是由于某种原因,我无法使用 KeyboardInterrupt
命令终止此脚本。
请问如何使用 KeyboardInterrupt
命令强制终止此脚本?为什么我无法使用 KeyboardInterrupt
命令终止它呢?
CTRL-C
关闭脚本。 - ZionCtrl
+Break
怎么样? - falsetru