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)
The net package lets your program talk to other computers over the internet using standard rules like TCP. Think of it as opening a digital phone line to send and receive messages with a server. You use it whenever your application needs to fetch data from a website or send information to a remote service.