-
Book Overview & Buying
-
Table Of Contents
Practical Systems Programming in Go
By :
UDP provides a lightweight, connectionless transport service suitable for applications that can tolerate data loss in exchange for reduced overhead and latency. Applications using UDP must implement their own reliability mechanisms if needed, with common UDP applications including DNS queries, live video streaming, online gaming, and network management protocols. Developing a UDP server in Go leverages the handy net package. Unlike TCP, UDP does not require establishing a persistent connection; the server begins by creating a net.UDPAddr for the desired port, and then calls net.ListenUDP("udp", &addr) to start listening. The server can receive messages using conn.ReadFromUDP(buffer), which returns both the data and the address of the sender, and can respond with conn.WriteToUDP(response, clientAddr). By combining these calls in a loop, the server can handle multiple incoming datagrams, echoing data back to clients or generating dynamic responses such...