blob: ea704bd61870fa12d9af98d8d0602861b820d534 [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
nickhuang6b31f8f2019-09-26 02:02:14 +000025 conn, _ := net.Dial("tcp", "127.0.0.1:9999")
26 reader := bufio.NewReader(os.Stdin)
27 for {
28 // read in input from stdin
mc20a4b5f2019-10-16 20:28:24 +000029 fmt.Print("CMD to send : ")
mccd7e9502019-12-16 22:04:13 +000030 text, _ := reader.ReadString(';')
31 text = strings.TrimSuffix(text, ";")
nickhuang6b31f8f2019-09-26 02:02:14 +000032 // send to socket
Dinesh Belwalkar72ecafb2019-12-12 00:08:56 +000033 fmt.Fprintf(conn, text+"\n")
nickhuang6b31f8f2019-09-26 02:02:14 +000034
mc20a4b5f2019-10-16 20:28:24 +000035 // listen for reply
Dinesh Belwalkara6ba07d2020-01-10 23:22:34 +000036 message, _ := bufio.NewReader(conn).ReadString('\n')
mc20a4b5f2019-10-16 20:28:24 +000037 fmt.Print("Return from server: " + message)
nickhuang6b31f8f2019-09-26 02:02:14 +000038
Dinesh Belwalkar72ecafb2019-12-12 00:08:56 +000039 if message == "QUIT\n" {
nickhuang6b31f8f2019-09-26 02:02:14 +000040 break
41 }
42 }
43}