From 7dbb61f295f4debaf6225eb9d4df549b08b73d81 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Thu, 26 Jul 2018 21:58:09 +0300 Subject: [PATCH] try to reconnect when server is not yet started Related #106 --- client.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index 72b0880a..9c421606 100644 --- a/client.go +++ b/client.go @@ -8,6 +8,7 @@ import ( "net" "os" "strings" + "time" "github.com/nsf/termbox-go" ) @@ -53,10 +54,14 @@ func readExpr() <-chan expr { ch := make(chan expr) go func() { + duration := 1 * time.Second + c, err := net.Dial(gSocketProt, gSocketPath) - if err != nil { + for err != nil { log.Printf(fmt.Sprintf("connecting server: %s", err)) - return + c, err = net.Dial(gSocketProt, gSocketPath) + time.Sleep(duration) + duration *= 2 } fmt.Fprintf(c, "conn %d\n", gClientID)