The purpose of the UDP server that is going to be developed in this section is returning random numbers between 1 and 1,000 to its UDP clients. The name of the program is UDPserver.go, and it is presented in four segments.
The first part of UDPserver.go is as follows:
package main
import (
"fmt"
"math/rand"
"net"
"os"
"strconv"
"strings"
"time"
)
func random(min, max int) int {
return rand.Intn(max-min) + min
}
The second segment of UDPserver.go is as follows:
func main() {
arguments := os.Args
if len(arguments) == 1 {
fmt.Println("Please provide a port number!")
return
}
PORT := ":" + arguments[1]
s, err := net.ResolveUDPAddr("udp4", PORT)
if err != nil { ...