go:stdlib:net_dial
Table of Contents
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`.
Related pages
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)
go/stdlib/net_dial.txt · Last modified: by phong2018
