kinda works better

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-09 20:46:44 -07:00
parent b932251092
commit 562b20cbb4
1 changed files with 11 additions and 22 deletions

View File

@ -55,7 +55,8 @@ func socketToWIT(myhostname string) {
log.Println("socket connected to", CONN_PROTO, CONN_HOST, CONN_PORT) 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() connStdin, _ := conn.File()
@ -64,38 +65,26 @@ func socketToWIT(myhostname string) {
// read in input from stdin // read in input from stdin
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
for { for {
// read in the command to send to our server
fmt.Print("Text to send: ") fmt.Print("Text to send: ")
text, _ := reader.ReadString('\n') text, _ := reader.ReadString('\n')
// send to socket
fmt.Fprintf(conn, text + "\n") // send the command over the socket socket
a, err := connStdin.Write([]byte(string(text + "\n"))) a, err := conn.Write([]byte(string(text + "\n")))
// a, err := connStdin.Write([]byte(string(text + "\n")))
if (err != nil) { if (err != nil) {
fmt.Println("SOCKET DIED with err=", err, a) fmt.Println("SOCKET DIED with err=", err, a)
return 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() { func retrySocket() {
for { for {
log.Println("Sleep for 1 seconds, then try to establish connection to WIT") log.Println("Sleep for 3 seconds, then try to establish connection to WIT")
time.Sleep(1 * 1000 * 1000 * 1000) time.Sleep(3 * 1000 * 1000 * 1000)
// for now, loop until I figure out what to actually do // for now, loop until I figure out what to actually do
socketToWIT("librem15.lab.wit.com") socketToWIT("librem15.lab.wit.com")
} }