From 562b20cbb464677dc5a066e782c59dc169ee7f33 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 9 May 2019 20:46:44 -0700 Subject: [PATCH] kinda works better Signed-off-by: Jeff Carr --- socketWIT.go | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/socketWIT.go b/socketWIT.go index 59301c2..dee3d6a 100644 --- a/socketWIT.go +++ b/socketWIT.go @@ -55,7 +55,8 @@ func socketToWIT(myhostname string) { log.Println("socket connected to", CONN_PROTO, CONN_HOST, CONN_PORT) - fmt.Fprintf(conn, myhostname + "\n") + tmp, err := conn.Write([]byte(string(myhostname + "\n"))) + log.Println("conn.Write:", tmp, err) connStdin, _ := conn.File() @@ -64,38 +65,26 @@ func socketToWIT(myhostname string) { // read in input from stdin reader := bufio.NewReader(os.Stdin) for { + // read in the command to send to our server fmt.Print("Text to send: ") text, _ := reader.ReadString('\n') - // send to socket - fmt.Fprintf(conn, text + "\n") - a, err := connStdin.Write([]byte(string(text + "\n"))) + + // send the command over the socket socket + a, err := conn.Write([]byte(string(text + "\n"))) + + // a, err := connStdin.Write([]byte(string(text + "\n"))) if (err != nil) { fmt.Println("SOCKET DIED with err=", err, a) return } - // TODO: check the socket has died and exit here } -/* - // listen for reply - - newreader := bufio.NewReader(newStdin) - - for { - message, err := newreader.ReadString('\n') - fmt.Println("Message from server: ", message) - if (err != nil) { - fmt.Println("SOCKET DIED with err=", err) - return - } - } - } -*/ } func retrySocket() { for { - log.Println("Sleep for 1 seconds, then try to establish connection to WIT") - time.Sleep(1 * 1000 * 1000 * 1000) + log.Println("Sleep for 3 seconds, then try to establish connection to WIT") + time.Sleep(3 * 1000 * 1000 * 1000) + // for now, loop until I figure out what to actually do socketToWIT("librem15.lab.wit.com") }