From 0067c550031d90b67c5a5f8f5e7d18d8cbd10c63 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 11 May 2019 10:55:37 -0700 Subject: [PATCH] remove old code. Attempt to send a protobuf over the socket Signed-off-by: Jeff Carr --- channel.go | 19 +++++++++++++++++++ infoTabUI.go | 8 ++++++++ socketWIT.go | 41 +++++++++++++---------------------------- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/channel.go b/channel.go index 88ac442..bb333fc 100644 --- a/channel.go +++ b/channel.go @@ -66,4 +66,23 @@ func addEvent() { err = proto.Unmarshal(data, pdata) mychannel <- pdata // sendDataToDest(data) + // writeBytesToSocket(data) +} + +func createProtobufEvent() *pb.Event { + msg := new(pb.Event) + msg.Name = "hello jeff" + + return msg +} + +func sendEventToWIT() { + msg := createProtobufEvent() + var mybuf []byte + + mybuf, err := proto.Marshal(msg) + if (err != nil) { + log.Printf("something fucked up happened") + } + writeBytesToSocket(mybuf) } diff --git a/infoTabUI.go b/infoTabUI.go index caa2ba6..1470e89 100644 --- a/infoTabUI.go +++ b/infoTabUI.go @@ -55,6 +55,7 @@ func makeCloudInfoBox() ui.Control { // ATTEMPT TO ADD THE TABLE HERE END hbox.Append(ui.NewVerticalSeparator(), false) + // Send a test protobuf Event to localhost add3button := ui.NewButton("Add buf to chann") add3button.OnClicked(func(*ui.Button) { log.Println("add protobuf event to the channel") @@ -62,6 +63,13 @@ func makeCloudInfoBox() ui.Control { }) vbox.Append(add3button, false) + // Send a protobuf Event over the WIT socket + add4button := ui.NewButton("Send protobuf") + add4button.OnClicked(func(*ui.Button) { + log.Println("sent a protobuf over the TCP socket") + sendEventToWIT() + }) + vbox.Append(add4button, false) hbox.Append(ui.NewVerticalSeparator(), false) diff --git a/socketWIT.go b/socketWIT.go index 26ea61c..0707c74 100644 --- a/socketWIT.go +++ b/socketWIT.go @@ -6,7 +6,7 @@ import "time" import "net" import "fmt" import "bufio" -import "strings" +// import "strings" import "git.wit.com/wit/shell" import "git.wit.com/jcarr/dnssecsocket" @@ -27,19 +27,28 @@ const ( func writelnToSocket(aline string) { if connCurrent == nil { - fmt.Println("SOCKET IS NOT CONNECTED") + log.Println("SOCKET IS NOT CONNECTED") return } // a, err := connCurrent.Write([]byte(string(text + "\n"))) a, err := connCurrent.Write([]byte(string(aline + "\n"))) if err != nil { - fmt.Println("SOCKET WRITE FAILED with err=", err, a) + log.Println("SOCKET WRITE FAILED with err=", err, a) connCurrent = nil return } } +func writeBytesToSocket(data []byte) { + if (connCurrent == nil) { + log.Println("WIT Socket is currently down (connCurrent == nil)") + return + } + a, err := connCurrent.Write(data) + log.Println("WIT Socket Write() returned:", a, err) +} + func socketToWIT(myhostname string) { remoteAddr := CONN_HOST + ":" + CONN_PORT log.Println("remoteAddr:", remoteAddr) @@ -83,32 +92,8 @@ func socketToWIT(myhostname string) { connCurrent = conn newreader := bufio.NewReader(connStdin) - go shell.NonBlockingReader(newreader, os.Stdout) - // 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') - - text = strings.TrimSpace(text) // this is like perl chomp - log.Println("LINE WAS:", text) - log.Println("LINE WAS:", text) - log.Println("LINE WAS:", text) - - if (text == "ADD2") { - add2() - continue - } - // send the command over the socket socket - a, err := conn.Write([]byte(string(text + "\n"))) - - if (err != nil) { - fmt.Println("SOCKET WRITE FAILED with err=", err, a) - return - } - } + shell.NonBlockingReader(newreader, os.Stdout) } func retrySocket() {