在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、代码 package main import ( "bufio" "fmt" "net" "os" "strings" ) func main() { ClientBase() } func ClientBase() { //open connection: conn, err := net.Dial("tcp", "127.0.0.1:60000") if err != nil { fmt.Println("Error dial:", err.Error()) return } inputReader := bufio.NewReader(os.Stdin) fmt.Println("Please input your name:") clientName, _ := inputReader.ReadString('\n') inputClientName := strings.Trim(clientName, "\n") //send info to server until Quit for { fmt.Println("What do you send to the server? Type Q to quit.") content, _ := inputReader.ReadString('\n') inputContent := strings.Trim(content, "\n") if inputContent == "Q" { return } _, err := conn.Write([]byte(inputClientName + " says " + inputContent)) if err != nil { fmt.Println("Error Write:", err.Error()) return } } } 2、运行效果
|
请发表评论