1 Star 0 Fork 0

bluesky2006/ssh

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
timeouts.go 779 Bytes
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"log"
"time"
"github.com/gliderlabs/ssh"
)
var (
DeadlineTimeout = 30 * time.Second
IdleTimeout = 10 * time.Second
)
func main() {
ssh.Handle(func(s ssh.Session) {
log.Println("new connection")
i := 0
for {
i += 1
log.Println("active seconds:", i)
select {
case <-time.After(time.Second):
continue
case <-s.Context().Done():
log.Println("connection closed")
return
}
}
})
log.Println("starting ssh server on port 2222...")
log.Printf("connections will only last %s\n", DeadlineTimeout)
log.Printf("and timeout after %s of no activity\n", IdleTimeout)
server := &ssh.Server{
Addr: ":2222",
MaxTimeout: DeadlineTimeout,
IdleTimeout: IdleTimeout,
}
log.Fatal(server.ListenAndServe())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/bluesky2006/ssh.git
git@gitee.com:bluesky2006/ssh.git
bluesky2006
ssh
ssh
v0.3.0

搜索帮助