github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/examples/echo/client.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"os"
     7  )
     8  
     9  func main() {
    10  	if len(os.Args) != 3 {
    11  		fmt.Printf("Usage: %s <host:port> <string>\n", os.Args[0])
    12  		return
    13  	}
    14  	serverAddr, msg := os.Args[1], os.Args[2]
    15  
    16  	c, err := net.Dial("tcp", serverAddr)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  	defer c.Close()
    21  
    22  	n, err := c.Write([]byte(msg))
    23  	if err != nil {
    24  		panic(err)
    25  	}
    26  	fmt.Println("write byte: ", n)
    27  
    28  	buf := make([]byte, 1024)
    29  	if _, err = c.Read(buf); err != nil {
    30  		panic(err)
    31  	}
    32  
    33  	fmt.Printf("echo: %s\n", buf)
    34  }