blob: e1ee3bbac3bae26124a828281bf22d3be6aee644 [file] [log] [blame]
nickhuang6b31f8f2019-09-26 02:02:14 +00001// Copyright 2018-present Open Networking Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import "net"
18import "fmt"
19import "bufio"
20import "os"
21import "strings"
22
23var attach_ip string = ""
24
25func main() {
26 // connect to this socket
27 var message string = ""
28 conn, _ := net.Dial("tcp", "127.0.0.1:9999")
29 reader := bufio.NewReader(os.Stdin)
30 for {
31 // read in input from stdin
32 if(attach_ip != ""){
33 fmt.Printf("[%v] CMD to send :", attach_ip)
34 }else{
35 fmt.Print("CMD to send :")
36 }
37 text, _ := reader.ReadString('\n')
38
39 // send to socket
40 fmt.Fprintf(conn, text + "\n")
41
42 cmd := strings.TrimSuffix(text, "\n")
43 s := strings.Split(cmd, ":")
44 cmd = s[0]
45
46 if(cmd == "attach"){
47 // listen for reply
48 t_attach_ip, _ := bufio.NewReader(conn).ReadString('\n')
49 attach_ip = strings.TrimSuffix(t_attach_ip, "\n")
50 }else{
51 // listen for reply
52 message, _ = bufio.NewReader(conn).ReadString('\n')
53 fmt.Print("Return from server: " + message)
54 }
55
56 if message == "QUIT\n"{
57 break
58 }
59 }
60}