Go supports networked communication at several levels. The standard library gives you raw sockets (net), HTTP (net/http) and a legacy RPC package (net/rpc). For service-to-service calls and messaging, Go programs usually add gRPC, a message broker client or WebSockets from third-party modules. Which one to pick depends on the use case, not on the language.
This guide compares the options, shows a UDP and a Unix socket example, and explains how to choose a protocol for common scenarios.
| Use case | Typical choice | Where it lives |
|---|---|---|
| Public REST or JSON API | HTTP with net/http | Standard library |
| Internal service-to-service calls with typed contracts | gRPC with Protocol Buffers | google.golang.org/grpc |
| Custom binary or text protocol | TCP with net | Standard library |
| Telemetry, discovery, low-latency datagrams | UDP with net | Standard library |
| Local inter-process communication | Unix domain sockets | Standard library |
| Server push to browsers | WebSockets or Server-Sent Events | SSE: standard library; WebSockets: third party |
| Asynchronous events and queues | Kafka, NATS, RabbitMQ clients | Third party |
The standard net/rpc package still works but is frozen and does not support modern features such as streaming or cross-language contracts. New systems use gRPC or plain HTTP instead.
Every network connection in Go implements net.Conn, whether it is TCP, TLS or a Unix socket. That means the same code can read and write over any of them.
TCP is a byte stream, so a single Read may return part of a message. Frame your messages with a length prefix, a delimiter such as a newline, or use bufio.Scanner and io.ReadFull.
UDP gives no delivery, ordering or retransmission guarantees. Use it only when losing a packet is acceptable or you add your own reliability.
Replace the network name with "unix" and the address with a file path:
The rest of the server code is identical to the TCP version, and access is controlled by file permissions.
For internal APIs, gRPC gives you generated clients, streaming and strict schemas. A client call looks like this once you have generated code from a .proto file:
grpc.NewClient replaced the older grpc.Dial in current grpc-go releases. If you do not need streaming or polyglot contracts, plain HTTP with JSON through net/http is simpler to debug and works everywhere.
context.Context through your call chain so cancellation reaches the network layer.errors.Is(err, net.ErrClosed) and errors.As for net.Error, whose Timeout() method tells you if a deadline fired.sync.WaitGroup.No. The package is frozen and Go-only. Use gRPC for typed RPC or HTTP with JSON for simplicity.
Use a message broker such as NATS, Kafka or RabbitMQ with its official or widely used Go client. The standard library has no message queue.
Yes. Go's runtime multiplexes goroutines over a network poller, so one goroutine per connection scales to very large connection counts.
Use net.LookupHost, net.LookupAddr, net.LookupMX and related functions, or net.Resolver when you need a custom resolver or context.
Go covers the transport layer with net, the application layer with net/http, and relies on well-supported modules for gRPC, WebSockets and messaging. Choose the protocol that matches your use case, always set deadlines and contexts, and remember that TCP is a stream while UDP is unreliable datagrams.