liveBook · Manning

UDP

As explained in Go in Practice, Second Edition

UDP is a connectionless transport-layer protocol that sends datagrams without guaranteeing delivery or ordering.

UDP is a connectionless transport-layer protocol that sends datagrams without guaranteeing delivery or ordering. It avoids connection maintenance and acknowledgment waits, making it useful when an application should keep sending despite a slow or unavailable receiver. section 7.3

Use UDP for logging when throughput and sender independence matter more than reliable delivery:

  • The client sends whenever it is ready and does not wait for server acknowledgments. section 7.3
  • A slow log server does not impose TCP-style back pressure on the client. section 7.3
  • The application remains less affected by log-server hiccups, although UDP packets may be lost. section 7.3

UDP-based logging in Go

Create a connection with net.DialTimeout("udp", "localhost:1902", 30*time.Second), defer its closure, and pass the connection to log.New. The logger can then write ordinary and panic messages directly to the UDP endpoint. Run a compatible listener with nc -luk 1902. The timeout mainly limits address resolution and message sending rather than waiting for an acknowledgment. section 7.3

Figure 7.2 UDP log messages, showing the relative simplicity compared to TCP. Messages receive no Ack from the server.
figure

Shows UDP log messages traveling without server acknowledgments, highlighting the protocol's simpler communication path compared with TCP. section 7.3

How Go in Practice, Second Edition covers it

How deep it goes
Shows a runnable Go sender, a timeout choice, a listener command, and practical benefits while leaving broader trade-offs unspecified.
Examples
Uses Go UDP logging with net.DialTimeout and a netcat listener on localhost port 1902.
What you can do after
Build UDP-based logging clients that tolerate receiver slowdowns and configure send timeouts.
How it connects
Contrasts UDP with TCP and places both alongside Go networking, net/http, WebSockets, and server applications.

Also explained in

Compare how 5 books explain UDP →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.