From 31c8c96c827c46e219e928e66d542e9c8f65bc6e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 9 Mar 2025 09:41:53 -0500 Subject: try to listen --- main.go | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 5b58e05..6d02a2b 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ package main import ( "embed" + "fmt" "io" "net" "os" @@ -50,24 +51,32 @@ func main() { } // go NewWatchdog() - - go listen3000() - go startHTTP() + if gui.NoGui() { + all := me.portmaps.All() + for all.Scan() { + pm := all.Next() + if !pm.Enabled { + continue + } + log.Info("portmap enabled for port", pm.Listen, "to", pm.Connect) + gus3000(int(pm.Listen), pm.Connect) + } os.Exit(0) } doGui() } -func listen3000() { +func gus3000(port int, connect string) { // Listen on local port 3000 - listener, err := net.Listen("tcp", "0.0.0.0:3000") + s := fmt.Sprintf("0.0.0.0:%d", port) + listener, err := net.Listen("tcp", s) if err != nil { - log.Fatalf("Failed to listen on port 3000: %v", err) + log.Fatalf("Failed to listen on %s: %v", s, err) } defer listener.Close() - log.Println("Listening on port 3000...") + log.Info("Listening on ", s) for { // Accept incoming connection @@ -79,17 +88,18 @@ func listen3000() { log.Printf("Client connected: %s", clientConn.RemoteAddr()) // Handle the connection in a separate goroutine - go handleConnection(clientConn) + go handleConnection(clientConn, s) } } -func handleConnection(clientConn net.Conn) { +func handleConnection(clientConn net.Conn, where string) { defer clientConn.Close() // Connect to the target server - targetConn, err := net.Dial("tcp", "go.wit.com:44355") + // targetConn, err := net.Dial("tcp", "go.wit.com:80") + targetConn, err := net.Dial("tcp", where) if err != nil { - log.Printf("Failed to connect to go.wit.com %v", err) + log.Printf("Failed to connect to %s %v", where, err) return } defer targetConn.Close() -- cgit v1.2.3