---
source: https://iinventedlight.com/library/notes/go-net-dial-listen.md
title: "Dial or listen for TCP in Go with the net package"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go docs); BSD-3-Clause (Go source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go docs, Package net; Go source, net.go package comment. BSD-3-Clause; BSD-3-Clause."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: Go net Dial Listen Accept"
tags: [go, net, tcp, listen, dial]
client: Librarian
sources:
  - id: S1
    title: "Package net"
    publisher: Go docs
    url: https://pkg.go.dev/net
    accessed: 2026-11-19
    license: "BSD-3-Clause"
  - id: S2
    title: "net.go package comment"
    publisher: Go source
    url: https://raw.githubusercontent.com/golang/go/master/src/net/net.go
    accessed: 2026-11-19
    license: "BSD-3-Clause"
---
# Dial or listen for TCP in Go with the net package
**Answer:** Package net provides a portable interface for network I/O, including TCP/IP also, UDP, domain name resolution, and Unix domain sockets. Most clients will need only the basic interface provided by the Dial, Listen, and Accept also functions and the associated Conn and Listener interfaces.

## Dial

The Dial function connects to a server. On error, handle the error before using the connection. The crypto/tls package uses the same interfaces and similar Dial and Listen functions.

## Listen

The Listen function creates servers. A loop can call Accept, then handle the Conn. Name resolution may happen with Dial or directly with LookupHost and LookupAddr. On Unix systems the resolver can use a pure Go resolver or a cgo-based resolver. A blocked DNS request in the pure Go resolver consumes only a goroutine.

| Dial | Listen |
|---|---|
| Dial | Connects to a server and returns a Conn |
| Listen | Creates a server Listener |
| Accept | Accepts the next incoming Conn |
| Conn | Interface for a network connection |
| Listener | Interface returned by Listen |

## See also

- [go-error-handling](https://iinventedlight.com/library/notes/go-error-handling/)
- [go-goroutines-channels](https://iinventedlight.com/library/notes/go-goroutines-channels/)
- [go-context](https://iinventedlight.com/library/notes/go-context/)

## Claims

- id: C1
  claim: The net package provides a portable interface for TCP, UDP, DNS, and Unix sockets.
  source: S1
  evidence: "portable interface for network I/O, including TCP/IP, UDP"

- id: C2
  claim: Most clients need only Dial, Listen, Accept, and the Conn and Listener interfaces.
  source: S2
  evidence: "basic interface provided by the [Dial], [Listen], and Accept functions"

- id: C3
  claim: The Listen function creates servers that accept connections.
  source: S2
  evidence: "The Listen function creates servers:"

## Sources

- [S1] Package net. Go docs. https://pkg.go.dev/net . License: BSD-3-Clause. Accessed 2026-11-19.

- [S2] net.go package comment. Go source. https://raw.githubusercontent.com/golang/go/master/src/net/net.go . License: BSD-3-Clause. Accessed 2026-11-19.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, Package net; Go source, net.go package comment. BSD-3-Clause; BSD-3-Clause. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
