
我尝试使用 Python 中的 socket 创建 Telnet 服务器,并使用 Telnet 进行远程控制。但是当我使用 send() 在 Telnet 客户端回显数据时,换行的数据会从上一行的末尾开始显示,就像
第一行 第二行 第三行 有没有办法能够让后面的行从一行的开头开始显示?
目前的代码:
class Telnet(threading.Thread): def __init__(self, conn, add): threading.Thread.__init__(self) self.inputstr = '' self.cOnnection= conn self.address = add def run(self): ii = 0 self.connection.send(b'Hello controller') self.connection.send(b'\n>') while True: buf = self.connection.recv(1024) if buf.rfind(b'\n') > -1: print("**-" + self.inputstr) return_arr = self.inputstr.split(' ') match return_arr[0]: case 'list': func_return = list_connections() for key in func_return.keys(): self.connection.send(key.encode()) self.inputstr = '' self.connection.send(b'\n>') else: self.inputstr += buf.decode() if ii == 0: self.connection.send(buf) ii += 1 continue 1 ysc3839 2022-10-22 13:05:32 +08:00 via Android telnet 协议的换行是 CRLF ,需要回车符(CR)把输出位置移动到行首 |