go - Why net.Conn use ioutil.ReadAll can't read -
first use ioutil.readall(conn)
can't read use io.copy
can
tcpaddr, _ := net.resolvetcpaddr("tcp4", ":7777") conn, _ := net.dialtcp("tcp4", nil, tcpaddr) scanner := bufio.newscanner(os.stdin) scanner.scan() { data := scanner.bytes() data = append(data, '\n') conn.write(data) go func(conn *net.tcpconn) { io.copy(os.stdout, conn) //res, _ := ioutil.readall(conn) //fmt.println("server = ", string(res)) }(conn) }
Comments
Post a Comment