diff --git a/README.md b/README.md index 96f05171c..44655899e 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Please use the current latest version: ## Submitting an issue -Please attach the output of the commands running at http://localhost:8989 if useful. +Please attach the output of the commands running at the debug console if useful. ## Submitting a pull request diff --git a/config.ini b/config.ini index 51c6b209d..f0639f2c6 100644 --- a/config.ini +++ b/config.ini @@ -1,4 +1,3 @@ -addr = :8989 # http service address configUpdateInterval = 0 # Update interval for re-reading config file set via -config flag. Zero disables config file re-reading. gc = std # Type of garbage collection. std = Normal garbage collection allowing system to decide (this has been known to cause a stop the world in the middle of a CNC job which can cause lost responses from the CNC controller and thus stalled jobs. use max instead to solve.), off = let memory grow unbounded (you have to send in the gc command manually to garbage collect or you will run out of RAM eventually), max = Force garbage collection on each recv or send on a serial port (this minimizes stop the world events and thus lost serial responses, but increases CPU usage) hostname = unknown-hostname # Override the hostname we get from the OS diff --git a/hub.go b/hub.go index 791e51331..022f7f9e3 100755 --- a/hub.go +++ b/hub.go @@ -321,7 +321,7 @@ func restart(path string) { hiberString = "-hibernate" } - cmd = exec.Command(exePath, "-ls", "-addr", *addr, "-regex", *regExpFilter, "-gc", *gcType, hiberString) + cmd = exec.Command(exePath, "-ls", "-regex", *regExpFilter, "-gc", *gcType, hiberString) fmt.Println(cmd) diff --git a/info.go b/info.go new file mode 100644 index 000000000..194d46e4c --- /dev/null +++ b/info.go @@ -0,0 +1,14 @@ +package main + +import ( + "github.com/gin-gonic/gin" +) + +func infoHandler(c *gin.Context) { + c.JSON(200, gin.H{ + "http": "http://localhost" + port, + "https": "https://localhost" + port, + "ws": "ws://localhost" + port, + "wss": "wss://localhost" + portSSL, + }) +} diff --git a/main.go b/main.go index 1989c3133..f68bc82cf 100755 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "os/user" "path/filepath" "runtime/debug" + "strconv" "text/template" "time" //"github.com/sanbornm/go-selfupdate/selfupdate" #included in update.go to change heavily @@ -26,8 +27,6 @@ var ( embedded_autoupdate = true embedded_autoextract = false hibernate = flag.Bool("hibernate", false, "start hibernated") - addr = flag.String("addr", ":8989", "http service address") - addrSSL = flag.String("addrSSL", ":8990", "https service address") verbose = flag.Bool("v", true, "show debug logging") //verbose = flag.Bool("v", false, "show debug logging") isLaunchSelf = flag.Bool("ls", false, "launch self 5 seconds later") @@ -41,6 +40,8 @@ var ( appName = flag.String("appName", "", "") globalToolsMap = make(map[string]string) tempToolsPath = createToolsDir() + port string + portSSL string ) type NullWriter int @@ -137,7 +138,6 @@ func main() { } } - f := flag.Lookup("addr") log.Println("Version:" + version) // hostname @@ -159,11 +159,6 @@ func main() { debug.SetGCPercent(-1) } - ip := "0.0.0.0" - log.Print("Starting server and websocket on " + ip + "" + f.Value.String()) - - log.Println("The Arduino Create Agent is now running") - // see if they provided a regex filter if len(*regExpFilter) > 0 { log.Printf("You specified a serial port regular expression filter: %v\n", *regExpFilter) @@ -214,17 +209,43 @@ func main() { r.POST("/socket.io/", socketHandler) r.Handle("WS", "/socket.io/", socketHandler) r.Handle("WSS", "/socket.io/", socketHandler) + r.GET("/info", infoHandler) go func() { - if err := r.RunTLS(*addrSSL, filepath.Join(dest, "cert.pem"), filepath.Join(dest, "key.pem")); err != nil { - log.Printf("Error trying to bind to port: %v, so exiting...", err) - log.Fatal("Error ListenAndServe:", err) + start := 49152 + end := 65535 + i := start + for i < end { + i = i + 1 + portSSL = ":" + strconv.Itoa(i) + if err := r.RunTLS(portSSL, filepath.Join(dest, "cert.pem"), filepath.Join(dest, "key.pem")); err != nil { + log.Printf("Error trying to bind to port: %v, so exiting...", err) + continue + } else { + ip := "0.0.0.0" + log.Print("Starting server and websocket (SSL) on " + ip + "" + port) + break + } + } + }() + + go func() { + start := 49152 + end := 65535 + i := start + for i < end { + i = i + 1 + port = ":" + strconv.Itoa(i) + if err := r.Run(port); err != nil { + log.Printf("Error trying to bind to port: %v, so exiting...", err) + continue + } else { + ip := "0.0.0.0" + log.Print("Starting server and websocket on " + ip + "" + port) + break + } } }() - if err := r.Run(*addr); err != nil { - log.Printf("Error trying to bind to port: %v, so exiting...", err) - log.Fatal("Error ListenAndServe:", err) - } }() } setupSysTray() diff --git a/trayicon.go b/trayicon.go index d0cde47d3..19fb92b06 100644 --- a/trayicon.go +++ b/trayicon.go @@ -91,7 +91,7 @@ func setupSysTrayReal() { for { <-mDebug.ClickedCh logAction("log on") - open.Start("http://localhost:8989") + open.Start("http://localhost" + port) } }()