loop through attempts to connect every 10 seconds
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
629de89203
commit
64223c47cd
52
main.go
52
main.go
|
@ -3,6 +3,9 @@ package main
|
||||||
import "log"
|
import "log"
|
||||||
import "os"
|
import "os"
|
||||||
import "time"
|
import "time"
|
||||||
|
import "net"
|
||||||
|
import "fmt"
|
||||||
|
import "bufio"
|
||||||
|
|
||||||
import "github.com/gookit/config"
|
import "github.com/gookit/config"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
|
@ -29,10 +32,57 @@ import "github.com/davecgh/go-spew/spew"
|
||||||
// always sorted slice (new project)
|
// always sorted slice (new project)
|
||||||
// https://github.com/yaa110/sslice
|
// 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 doGUI() {
|
||||||
|
ui.Main(setupUI)
|
||||||
|
|
||||||
|
log.Println("GUI exited. Not sure what to do here. os.Exit() ?")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
parseConfig()
|
parseConfig()
|
||||||
|
|
||||||
ui.Main(setupUI)
|
go doGUI()
|
||||||
|
|
||||||
|
|
||||||
|
for {
|
||||||
|
log.Println("Sleep for 10 seconds, then try to establish connection to WIT")
|
||||||
|
time.Sleep(10 * 1000 * 1000 * 1000)
|
||||||
|
// for now, loop until I figure out what to actually do
|
||||||
|
socketToWIT()
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("Sleep for 1 second")
|
log.Println("Sleep for 1 second")
|
||||||
time.Sleep(1 * 1000 * 1000 * 1000)
|
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||||
|
|
Loading…
Reference in New Issue