How to use net package for TCP

Use net.Dial to establish a TCP connection and the Conn interface to read and write data.

Use net.Dial to create a TCP connection, then read and write data using the returned net.Conn interface.

conn, err := net.Dial("tcp", "example.com:80")
if err != nil {
    panic(err)
}
defer conn.Close()
conn.Write([]byte("GET / HTTP/1.0\r\n\r\n"))
buf := make([]byte, 1024)
conn.Read(buf)