blob: da19079a6eb659111ed511d21698180ae13988ae [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"
mccd7e9502019-12-16 22:04:13 +000021import "strings"
nickhuang6b31f8f2019-09-26 02:02:14 +000022
23func main() {
24 // connect to this socket
25 var message string = ""
26 conn, _ := net.Dial("tcp", "127.0.0.1:9999")
27 reader := bufio.NewReader(os.Stdin)
28 for {
29 // read in input from stdin
mc20a4b5f2019-10-16 20:28:24 +000030 fmt.Print("CMD to send : ")
mccd7e9502019-12-16 22:04:13 +000031 text, _ := reader.ReadString(';')
32 text = strings.TrimSuffix(text, ";")
nickhuang6b31f8f2019-09-26 02:02:14 +000033 // send to socket
Dinesh Belwalkar72ecafb2019-12-12 00:08:56 +000034 fmt.Fprintf(conn, text+"\n")
nickhuang6b31f8f2019-09-26 02:02:14 +000035
mc20a4b5f2019-10-16 20:28:24 +000036 // listen for reply
37 message, _ = bufio.NewReader(conn).ReadString('\n')
38 fmt.Print("Return from server: " + message)
nickhuang6b31f8f2019-09-26 02:02:14 +000039
Dinesh Belwalkar72ecafb2019-12-12 00:08:56 +000040 if message == "QUIT\n" {
nickhuang6b31f8f2019-09-26 02:02:14 +000041 break
42 }
43 }
44}