summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-03-09 06:32:14 -0500
committerJeff Carr <[email protected]>2025-03-09 06:32:14 -0500
commiteaedaded622316d3b59c2f3765cd2362e96ce54c (patch)
tree483f1d67ecc990c1079bbccbfc9d89106332abfe /main.go
parent93852523e66c2646c8997c014f7c060b7baf0df8 (diff)
make a portmap protobuf & ConfigSave()
Diffstat (limited to 'main.go')
-rw-r--r--main.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/main.go b/main.go
index 5264b69..e5ea927 100644
--- a/main.go
+++ b/main.go
@@ -4,6 +4,8 @@
package main
import (
+ "io"
+ "net"
"os"
"time"
@@ -35,5 +37,47 @@ func main() {
// go NewWatchdog()
+ go listen3000()
+
startHTTP()
}
+
+func listen3000() {
+ // Listen on local port 3000
+ listener, err := net.Listen("tcp", "0.0.0.0:3000")
+ if err != nil {
+ log.Fatalf("Failed to listen on port 3000: %v", err)
+ }
+ defer listener.Close()
+ log.Println("Listening on port 3000...")
+
+ for {
+ // Accept incoming connection
+ clientConn, err := listener.Accept()
+ if err != nil {
+ log.Printf("Failed to accept client connection: %v", err)
+ continue
+ }
+ log.Printf("Client connected: %s", clientConn.RemoteAddr())
+
+ // Handle the connection in a separate goroutine
+ go handleConnection(clientConn)
+ }
+}
+
+func handleConnection(clientConn net.Conn) {
+ defer clientConn.Close()
+
+ // Connect to the target server
+ targetConn, err := net.Dial("tcp", "go.wit.com:44355")
+ if err != nil {
+ log.Printf("Failed to connect to go.wit.com %v", err)
+ return
+ }
+ defer targetConn.Close()
+ log.Printf("Connected to target server: %s", targetConn.RemoteAddr())
+
+ // Bidirectional copy of data
+ go io.Copy(targetConn, clientConn) // Client -> Target
+ io.Copy(clientConn, targetConn) // Target -> Client
+}