nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 1 | // 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 | |
| 15 | package main |
| 16 | |
| 17 | import "net" |
| 18 | import "fmt" |
| 19 | import "bufio" |
| 20 | import "os" |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 21 | |
| 22 | func main() { |
| 23 | // connect to this socket |
| 24 | var message string = "" |
| 25 | conn, _ := net.Dial("tcp", "127.0.0.1:9999") |
| 26 | reader := bufio.NewReader(os.Stdin) |
| 27 | for { |
| 28 | // read in input from stdin |
mc | 20a4b5f | 2019-10-16 20:28:24 +0000 | [diff] [blame^] | 29 | fmt.Print("CMD to send : ") |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 30 | text, _ := reader.ReadString('\n') |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 31 | // send to socket |
| 32 | fmt.Fprintf(conn, text + "\n") |
| 33 | |
mc | 20a4b5f | 2019-10-16 20:28:24 +0000 | [diff] [blame^] | 34 | // listen for reply |
| 35 | message, _ = bufio.NewReader(conn).ReadString('\n') |
| 36 | fmt.Print("Return from server: " + message) |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 37 | |
| 38 | if message == "QUIT\n"{ |
| 39 | break |
| 40 | } |
| 41 | } |
| 42 | } |