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" |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame^] | 21 | import "strings" |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 22 | |
| 23 | func 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 |
mc | 20a4b5f | 2019-10-16 20:28:24 +0000 | [diff] [blame] | 30 | fmt.Print("CMD to send : ") |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame^] | 31 | text, _ := reader.ReadString(';') |
| 32 | text = strings.TrimSuffix(text, ";") |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 33 | // send to socket |
Dinesh Belwalkar | 72ecafb | 2019-12-12 00:08:56 +0000 | [diff] [blame] | 34 | fmt.Fprintf(conn, text+"\n") |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 35 | |
mc | 20a4b5f | 2019-10-16 20:28:24 +0000 | [diff] [blame] | 36 | // listen for reply |
| 37 | message, _ = bufio.NewReader(conn).ReadString('\n') |
| 38 | fmt.Print("Return from server: " + message) |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 39 | |
Dinesh Belwalkar | 72ecafb | 2019-12-12 00:08:56 +0000 | [diff] [blame] | 40 | if message == "QUIT\n" { |
nickhuang | 6b31f8f | 2019-09-26 02:02:14 +0000 | [diff] [blame] | 41 | break |
| 42 | } |
| 43 | } |
| 44 | } |