Developing a simple UDP client

In this section, we will develop a UDP client, which we will name UDPclient.go and present in five parts.

As you will see, the code differences between the Go code of UDPclient.go and TCPc.go are basically the differences in the names of the functions used: the general idea is exactly the same.

The first part of the UDP client is the following:

package main 
 
import ( 
   "fmt" 
   "net" 
   "os" 
) 

The second part of the utility contains the following Go code:

func main() { 
   arguments := os.Args 
   if len(arguments) == 1 { 
         fmt.Println("Please provide a host:port string") 
         os.Exit(100) 
   } 
   CONNECT := arguments[1] 

The third part of UDPclient.go has the following Go code:

 s, err := net.ResolveUDPAddr("udp", CONNECT) c, err := net.DialUDP("udp", ...

Get Go Systems Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.