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:
parent
a737a23d6f
commit
0067c55003
19
channel.go
19
channel.go
|
@ -66,4 +66,23 @@ func addEvent() {
|
||||||
err = proto.Unmarshal(data, pdata)
|
err = proto.Unmarshal(data, pdata)
|
||||||
mychannel <- pdata
|
mychannel <- pdata
|
||||||
// sendDataToDest(data)
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ func makeCloudInfoBox() ui.Control {
|
||||||
// ATTEMPT TO ADD THE TABLE HERE END
|
// ATTEMPT TO ADD THE TABLE HERE END
|
||||||
hbox.Append(ui.NewVerticalSeparator(), false)
|
hbox.Append(ui.NewVerticalSeparator(), false)
|
||||||
|
|
||||||
|
// Send a test protobuf Event to localhost
|
||||||
add3button := ui.NewButton("Add buf to chann")
|
add3button := ui.NewButton("Add buf to chann")
|
||||||
add3button.OnClicked(func(*ui.Button) {
|
add3button.OnClicked(func(*ui.Button) {
|
||||||
log.Println("add protobuf event to the channel")
|
log.Println("add protobuf event to the channel")
|
||||||
|
@ -62,6 +63,13 @@ func makeCloudInfoBox() ui.Control {
|
||||||
})
|
})
|
||||||
vbox.Append(add3button, false)
|
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)
|
hbox.Append(ui.NewVerticalSeparator(), false)
|
||||||
|
|
||||||
|
|
41
socketWIT.go
41
socketWIT.go
|
@ -6,7 +6,7 @@ import "time"
|
||||||
import "net"
|
import "net"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "bufio"
|
import "bufio"
|
||||||
import "strings"
|
// import "strings"
|
||||||
|
|
||||||
import "git.wit.com/wit/shell"
|
import "git.wit.com/wit/shell"
|
||||||
import "git.wit.com/jcarr/dnssecsocket"
|
import "git.wit.com/jcarr/dnssecsocket"
|
||||||
|
@ -27,19 +27,28 @@ const (
|
||||||
|
|
||||||
func writelnToSocket(aline string) {
|
func writelnToSocket(aline string) {
|
||||||
if connCurrent == nil {
|
if connCurrent == nil {
|
||||||
fmt.Println("SOCKET IS NOT CONNECTED")
|
log.Println("SOCKET IS NOT CONNECTED")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// a, err := connCurrent.Write([]byte(string(text + "\n")))
|
// a, err := connCurrent.Write([]byte(string(text + "\n")))
|
||||||
a, err := connCurrent.Write([]byte(string(aline + "\n")))
|
a, err := connCurrent.Write([]byte(string(aline + "\n")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("SOCKET WRITE FAILED with err=", err, a)
|
log.Println("SOCKET WRITE FAILED with err=", err, a)
|
||||||
connCurrent = nil
|
connCurrent = nil
|
||||||
return
|
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) {
|
func socketToWIT(myhostname string) {
|
||||||
remoteAddr := CONN_HOST + ":" + CONN_PORT
|
remoteAddr := CONN_HOST + ":" + CONN_PORT
|
||||||
log.Println("remoteAddr:", remoteAddr)
|
log.Println("remoteAddr:", remoteAddr)
|
||||||
|
@ -83,32 +92,8 @@ func socketToWIT(myhostname string) {
|
||||||
connCurrent = conn
|
connCurrent = conn
|
||||||
|
|
||||||
newreader := bufio.NewReader(connStdin)
|
newreader := bufio.NewReader(connStdin)
|
||||||
go shell.NonBlockingReader(newreader, os.Stdout)
|
|
||||||
|
|
||||||
// read in input from stdin
|
shell.NonBlockingReader(newreader, os.Stdout)
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrySocket() {
|
func retrySocket() {
|
||||||
|
|
Loading…
Reference in New Issue