make a button to send a protobuf to a local socket

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-11 13:20:51 -07:00
parent b49aed2de0
commit 2330e0a2b6
2 changed files with 43 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import "net"
import "os"
import "io"
import "bytes"
import "strconv"
import "github.com/golang/protobuf/proto"
import pb "git.wit.com/wit/witProtobuf"
@ -55,18 +56,18 @@ func addEvent() {
msg := pb.CreateSampleEvent()
msg.Name = "generated in addEvent()"
// var mybuf bytes.Buffer
data, err := proto.Marshal(msg)
if (err != nil) {
log.Printf("something fucked up happened")
log.Printf("addEvent() something fucked up happened in Marshal")
}
pdata := new(pb.Event)
// err = proto.Unmarshal(data.Bytes(), pdata)
err = proto.Unmarshal(data, pdata)
if (err != nil) {
log.Printf("addEvent() something fucked up happened in Unmarshal")
}
mychannel <- pdata
// sendDataToDest(data)
// writeBytesToSocket(data)
}
func sendEventToWIT() {
@ -79,3 +80,30 @@ func sendEventToWIT() {
}
writeBytesToSocket(mybuf)
}
func sendDataToDest() {
msg := pb.CreateSampleEvent()
msg.Name = "from dnssecsockettest()"
data, err := proto.Marshal(msg)
if (err != nil) {
log.Printf("something fucked up happened")
}
conn, err := net.Dial("tcp", "localhost:8080")
if err != nil {
log.Println("Fatal error: %s", err.Error())
return
}
n, err := conn.Write(data)
if err != nil {
// fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
log.Println("Fatal error: %s", err.Error())
return
}
pb.DumpEventData(msg)
log.Println("Sent " + strconv.Itoa(n) + " bytes")
// time.Sleep(3 * 1000 * 1000 * 1000)
conn.Close()
}

View File

@ -53,6 +53,7 @@ func makeCloudInfoBox() ui.Control {
})
vbox.Append(add2button, false)
// ATTEMPT TO ADD THE TABLE HERE END
hbox.Append(ui.NewVerticalSeparator(), false)
// Send a test protobuf Event to localhost
@ -71,6 +72,14 @@ func makeCloudInfoBox() ui.Control {
})
vbox.Append(add4button, false)
// Send a protobuf Event over the WIT socket
add5button := ui.NewButton("Send protobuf to localhost")
add5button.OnClicked(func(*ui.Button) {
log.Println("sent a Marshal'd protobuf to a localhost socket")
sendDataToDest()
})
vbox.Append(add5button, false)
hbox.Append(ui.NewVerticalSeparator(), false)
vbox = ui.NewVerticalBox()