does multiline socket reads
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
91b9a337e9
commit
4863991462
5
Makefile
5
Makefile
|
@ -1,3 +1,6 @@
|
|||
run:
|
||||
go build
|
||||
./cloud-control-panel
|
||||
|
||||
gaper:
|
||||
# 'gaper' is a simple and smart golang tool that just rebuilds every time you change a file
|
||||
|
@ -5,7 +8,7 @@ gaper:
|
|||
gaper
|
||||
|
||||
#### NEVER DO THIS. THIS APPEARS TO INDUCE INSTABILITY IN GTK
|
||||
run:
|
||||
bad-run:
|
||||
#### NEVER DO THIS. THIS APPEARS TO INDUCE INSTABILITY IN GTK
|
||||
# go run *.go
|
||||
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
"jcarr": {
|
||||
"hostname": "fire.lab.wit.com",
|
||||
"port": 3333,
|
||||
"rows": 18,
|
||||
"proto": "tcp"
|
||||
},
|
||||
"v000185": {
|
||||
"hostname": "v000185.testing.com.customers.wprod.wit.com",
|
||||
"port": 3333,
|
||||
"rows": 567,
|
||||
"proto": "tcp"
|
||||
}
|
||||
},
|
||||
|
|
52
main.go
52
main.go
|
@ -3,9 +3,7 @@ package main
|
|||
import "log"
|
||||
import "os"
|
||||
import "time"
|
||||
import "net"
|
||||
import "fmt"
|
||||
import "bufio"
|
||||
|
||||
import "github.com/gookit/config"
|
||||
|
||||
|
@ -26,43 +24,11 @@ import "git.wit.com/wit/gui"
|
|||
// always sorted slice (new project)
|
||||
// https://github.com/yaa110/sslice
|
||||
|
||||
const (
|
||||
CONN_HOST = "v000185.testing.com.customers.wprod.wit.com"
|
||||
CONN_PORT = "3333"
|
||||
CONN_PROTO = "tcp"
|
||||
)
|
||||
|
||||
func socketToWIT() {
|
||||
// connect to this socket
|
||||
conn, err := net.Dial(CONN_PROTO, CONN_HOST+":"+CONN_PORT)
|
||||
|
||||
if err != nil {
|
||||
log.Println(CONN_HOST, CONN_PORT, CONN_PROTO)
|
||||
log.Println(err)
|
||||
log.Println("socket connect failed. Not sure what to do here. os.Exit() ?")
|
||||
return
|
||||
}
|
||||
|
||||
// read in input from stdin
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
fmt.Fprintf(conn,"librem15.lab.wit.com\n")
|
||||
|
||||
for {
|
||||
fmt.Print("Text to send: ")
|
||||
text, _ := reader.ReadString('\n')
|
||||
// send to socket
|
||||
fmt.Fprintf(conn, text + "\n")
|
||||
// listen for reply
|
||||
message, _ := bufio.NewReader(conn).ReadString('\n')
|
||||
fmt.Print("Message from server: "+message)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
parseConfig()
|
||||
|
||||
go gui.DoGUI()
|
||||
go retrySocket()
|
||||
|
||||
//
|
||||
// NOTE: This needs to be something long like 2 seconds.
|
||||
|
@ -74,7 +40,7 @@ func main() {
|
|||
|
||||
var parts []gui.InputData
|
||||
|
||||
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON"} {
|
||||
for key, foo := range []string{"BG", "TEXTCOLOR", "BUTTON", "TEXTCOLOR", "TEXTCOLOR", "TEXT", "BUTTON", "TEXT", "BUTTON"} {
|
||||
log.Println(key, foo)
|
||||
|
||||
var b gui.InputData
|
||||
|
@ -85,7 +51,7 @@ func main() {
|
|||
|
||||
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||
gui.AddTableTab("jcarr", 7, parts)
|
||||
gui.AddTableTab("test seven", 7, parts)
|
||||
|
||||
/*
|
||||
log.Println("Sleep for 1000 seconds, then try to add new tabs")
|
||||
|
@ -102,24 +68,22 @@ func main() {
|
|||
log.Println("Sleep for 2 seconds, then try to add new tabs")
|
||||
time.Sleep(2 * 1000 * 1000 * 1000)
|
||||
|
||||
rows := 4
|
||||
|
||||
for account, _ := range config.StringMap("cloud") {
|
||||
port := config.String("cloud." + account + ".port")
|
||||
proto := config.String("cloud." + account + ".proto")
|
||||
hostname := config.String("cloud." + account + ".hostname")
|
||||
fmt.Println(hostname, port, proto)
|
||||
rows := config.Int("cloud." + account + ".rows")
|
||||
fmt.Println(hostname, port, proto, rows)
|
||||
|
||||
gui.AddTableTab(account, rows, parts)
|
||||
rows = 700
|
||||
|
||||
log.Println("Sleep for 10 seconds, then add next table")
|
||||
time.Sleep(10 * 1000 * 1000 * 1000)
|
||||
}
|
||||
|
||||
for {
|
||||
log.Println("Sleep for 10 seconds, then try to establish connection to WIT")
|
||||
// TODO: figure out how to exit
|
||||
time.Sleep(10 * 1000 * 1000 * 1000)
|
||||
// for now, loop until I figure out what to actually do
|
||||
socketToWIT()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package main
|
||||
|
||||
import "log"
|
||||
import "os"
|
||||
import "time"
|
||||
import "net"
|
||||
import "fmt"
|
||||
import "bufio"
|
||||
|
||||
// import "github.com/gookit/config"
|
||||
// import "git.wit.com/wit/gui"
|
||||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
// reminder to use this for JSON
|
||||
// https://github.com/tidwall/gjson
|
||||
// value := gjson.Get(json, "name.last")
|
||||
// println(value.String())
|
||||
// value := gjson.Get(json, friends.#[last=="Murphy"].first)
|
||||
|
||||
// use mergo to merge structs
|
||||
// import "github.com/imdario/mergo"
|
||||
// mergo.Merge(&dest, src)
|
||||
|
||||
// always sorted slice (new project)
|
||||
// https://github.com/yaa110/sslice
|
||||
|
||||
const (
|
||||
CONN_HOST = "v000185.testing.com.customers.wprod.wit.com"
|
||||
CONN_PORT = "3333"
|
||||
CONN_PROTO = "tcp"
|
||||
)
|
||||
|
||||
func socketToWIT() {
|
||||
remoteAddr := CONN_HOST + ":" + CONN_PORT
|
||||
log.Println("remoteAddr:", remoteAddr)
|
||||
|
||||
// localAddr := "librem15.lab.wit.com" + ":" + CONN_PORT
|
||||
localAddr := "[2604:bbc0:3:3:0:10:0:1003]" + ":" + CONN_PORT
|
||||
log.Println("localAddr:", localAddr)
|
||||
|
||||
localTCPAddr, err := net.ResolveTCPAddr("tcp", localAddr)
|
||||
remoteTCPAddr, err := net.ResolveTCPAddr("tcp", remoteAddr)
|
||||
|
||||
// connect to this socket
|
||||
conn, err := net.DialTCP(CONN_PROTO, localTCPAddr, remoteTCPAddr)
|
||||
|
||||
if err != nil {
|
||||
log.Println(CONN_HOST, CONN_PORT, CONN_PROTO)
|
||||
log.Println(err)
|
||||
log.Println("socket connect failed. Not sure what to do here. os.Exit() ?")
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("socket connected to", CONN_PROTO, CONN_HOST, CONN_PORT)
|
||||
|
||||
// read in input from stdin
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
fmt.Fprintf(conn,"librem15.lab.wit.com\n")
|
||||
|
||||
for {
|
||||
fmt.Print("Text to send: ")
|
||||
text, _ := reader.ReadString('\n')
|
||||
// send to socket
|
||||
fmt.Fprintf(conn, text + "\n")
|
||||
// listen for reply
|
||||
|
||||
newStdin, _ := conn.File()
|
||||
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() {
|
||||
for {
|
||||
log.Println("Sleep for 1 seconds, then try to establish connection to WIT")
|
||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||
// for now, loop until I figure out what to actually do
|
||||
socketToWIT()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue