Server handling refactor (#27)

This commit is contained in:
2024-03-23 17:41:34 +01:00
committed by GitHub
parent db111642d2
commit 0c14419e7e
9 changed files with 77 additions and 85 deletions

View File

@ -5,17 +5,20 @@ import (
"time"
)
const scannerTimeOut = 3 * time.Second
type PortScanner struct {
Address net.Addr
}
func (p *PortScanner) IsPortOpen() (bool, error) {
conn, err := net.DialTimeout(p.Address.Network(), p.Address.String(), 3*time.Second)
conn, err := net.DialTimeout(p.Address.Network(), p.Address.String(), scannerTimeOut)
if err != nil {
return false, err
}
if conn != nil {
defer conn.Close()
}
return true, nil
}