我想用python制作telnet服务器。
这是我的服务器代码:
#!/usr/bin/python
import socket
SK = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = "192.168.1.10"
PORT = 23
SK.bind((HOST, PORT))
SK.listen(5)
(Attacker_connection, (Attacker_IP, Attacker_PORT)) = SK.accept()
while True:
Command = Attacker_connection.recv(4096)
Command = Command.decode("ascii")
if Command == "Quit":
break
和客户端测试命令:
telnet 192.168.1.10
但是服务器错误:
Traceback (most recent call last):
File "Telnet_H.py", line 18, in <module>
Command = Command.decode("ascii")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
客户端错误:
Trying 192.168.1.10...
Connected to 192.168.1.10.
Escape character is '^]'.
Connection closed by foreign host.
为什么会这样,我该如何解决?