fix: Telnet支持调整发送窗口大小
This commit is contained in:
@@ -119,12 +119,16 @@ func (c *ConnTelnet) RunCMD(cmd string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient 创建Telnet客户端会话对象
|
// NewClient 创建Telnet客户端会话对象
|
||||||
func (c *ConnTelnet) NewClientSession() (*TelnetClientSession, error) {
|
func (c *ConnTelnet) NewClientSession(cols, rows uint8) (*TelnetClientSession, error) {
|
||||||
if c.Client == nil {
|
if c.Client == nil {
|
||||||
return nil, fmt.Errorf("telnet client not connected")
|
return nil, fmt.Errorf("telnet client not connected")
|
||||||
}
|
}
|
||||||
conn := *c.Client
|
conn := *c.Client
|
||||||
|
|
||||||
|
// 需要确保接收方理解并正确处理发送窗口大小设置命令
|
||||||
|
conn.Write([]byte{255, 251, 31}) // 发送窗口大小选项
|
||||||
|
conn.Write([]byte{255, 250, 31, 0, rows, 0, cols, 255, 240}) // 发送窗口行和列的大小
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
tmp := make([]byte, 1024)
|
tmp := make([]byte, 1024)
|
||||||
// 排空连接登录的信息
|
// 排空连接登录的信息
|
||||||
|
|||||||
@@ -256,8 +256,19 @@ func (s *WSController) Telnet(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
|
// 终端单行字符数
|
||||||
|
cols, err := strconv.Atoi(c.Query("cols"))
|
||||||
|
if err != nil || cols > 254 {
|
||||||
|
cols = 80
|
||||||
|
}
|
||||||
|
// 终端显示行数
|
||||||
|
rows, err := strconv.Atoi(c.Query("rows"))
|
||||||
|
if err != nil || cols > rows {
|
||||||
|
rows = 40
|
||||||
|
}
|
||||||
|
|
||||||
// 创建Telnet客户端会话
|
// 创建Telnet客户端会话
|
||||||
clientSession, err := client.NewClientSession()
|
clientSession, err := client.NewClientSession(uint8(cols), uint8(rows))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 连接主机失败,请检查连接参数后重试
|
// 连接主机失败,请检查连接参数后重试
|
||||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "neHost.errByHostInfo")))
|
||||||
|
|||||||
Reference in New Issue
Block a user