User Tools

Site Tools


go:stdlib:net_dial

This is an old revision of the document!


net.Dial (TCP client connection)

What is it?

`net.Dial(network, address)` initiates an outgoing connection to `address` using the named `network`.

Common networks:

  • `“tcp”`
  • `“udp”`
  • `“unix”` (Unix domain sockets)

What is it used for?

  • Create a TCP client connection (e.g., to a server host:port).
  • Build low-level network clients.

Example (TCP)

package main
 
import (
    "net"
)
 
func main() {
    conn, err := net.Dial("tcp", "example.com:80")
    if err != nil {
        return
    }
    defer conn.Close()
}

Notes

  • `net.Listen()` is for servers.
  • `listener.Accept()` accepts incoming connections on the server side.
  • For timeouts, use `net.DialTimeout` or `Dialer`.

Hard words (English)

  • dial /ˈdaɪəl/: tạo kết nối (gọi ra)
  • initiate /ɪˈnɪʃieɪt/: khởi tạo
  • outgoing /ˈaʊtɡoʊɪŋ/: đi ra
  • listener /ˈlɪsənər/: đối tượng lắng nghe kết nối
  • socket /ˈsɑːkɪt/: ổ cắm mạng (điểm kết nối)

</dokuwiki>

go/stdlib/net_dial.1767909663.txt.gz · Last modified: by phong2018