fix: telnet连接不一定支持调整窗口大小先移除

This commit is contained in:
TsMask
2024-09-12 19:45:33 +08:00
parent c58b987a23
commit cb6f8ea382
10 changed files with 13 additions and 23 deletions

View File

@@ -50,11 +50,6 @@ func (c *ConnTelnet) NewClient() (*ConnTelnet, error) {
// fmt.Fprintln(client, c.User)
// fmt.Fprintln(client, c.Password)
// 调整窗口大小 (120 列 x 128 行)
// 需要确保接收方理解并正确处理发送窗口大小设置命令
client.Write([]byte{255, 251, 31})
client.Write([]byte{255, 250, 31, byte(120 >> 8), byte(120 & 0xFF), byte(128 >> 8), byte(128 & 0xFF), 255, 240})
c.Client = &client
// 排空连接登录的信息
@@ -116,6 +111,6 @@ func (c *ConnTelnet) NewClientSession(cols, rows int) (*TelnetClientSession, err
s := &TelnetClientSession{
Client: *c.Client,
}
s.WindowChange(cols, rows)
// s.WindowChange(cols, rows)
return s, nil
}

View File

@@ -47,11 +47,11 @@ func (s *TelnetClientSession) Read() []byte {
buf := make([]byte, 1024)
// 设置读取超时时间为100毫秒
s.Client.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
_, err := s.Client.Read(buf)
n, err := s.Client.Read(buf)
if err != nil {
return []byte{}
}
return buf
return buf[:n]
}
// CombinedOutput 发送命令带结果返回