port occupied detection

This commit is contained in:
josc146
2023-11-03 21:18:42 +08:00
parent fed1594ddc
commit 0d99e5549e
6 changed files with 39 additions and 6 deletions

View File

@@ -5,12 +5,15 @@ import (
"bufio"
"embed"
"errors"
"fmt"
"io"
"io/fs"
"net"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
)
@@ -205,3 +208,12 @@ func Unzip(source, destination string) error {
}
return nil
}
func (a *App) IsPortAvailable(port int) bool {
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%s", strconv.Itoa(port)))
if err != nil {
return false
}
defer l.Close()
return true
}