remove old <STDIN> code. Attempt to send a protobuf over the socket

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-11 10:55:37 -07:00
parent a737a23d6f
commit 0067c55003
3 changed files with 40 additions and 28 deletions

View File

@ -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)
}

View File

@ -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)

View File

@ -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() {