1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| package main
import ( "bufio" "fmt" "net" "os" "strings" )
func send_data(terminal_reader *bufio.Reader,connect net.Conn) { for { str, err := terminal_reader.ReadString('\n') if err != nil { fmt.Println("Read string Error:", err) } str = strings.Trim(str, "\r\n") _, err = connect.Write([]byte(str)) if err != nil { fmt.Println("Send Data Failed", err) } else { fmt.Println("Send data successs!!") } if str == "exit"{ return } } }
func main(){ var forward_ip string = "127.0.0.1" var forward_port string = "8888" conn,err := net.Dial("tcp",fmt.Sprintf("%s:%s",forward_ip,forward_port)) if err != nil { fmt.Println("Client Dial Error:",err) } defer conn.Close() terminal_reader := bufio.NewReader(os.Stdin) send_data(terminal_reader, conn)
}
|