package main import ( "net" "fmt" ) func main() { addr := "example.com:80" conn, err := net.Dial("tcp", addr) if err != nil { fmt.Printf("failed to connect to server %s: %v\n", addr, err) return } defer conn.Close() msg := "GET / HTTP/1.1\r\nHost: example.com\r\n\r\n" _, err = conn.Write([]byte(msg)) if err != nil { fmt.Printf("failed to send request to server %s: %v\n", addr, err) } }
package main import ( "net" "fmt" ) func main() { port := ":5000" addr, err := net.ResolveUDPAddr("udp", port) if err != nil { fmt.Printf("failed to resolve address %s: %v\n", addr, err) return } conn, err := net.ListenUDP("udp", addr) if err != nil { fmt.Printf("failed to listen on port %s: %v\n", port, err) return } defer conn.Close() buf := make([]byte, 1024) n, _, err := conn.ReadFromUDP(buf) if err != nil { fmt.Printf("failed to read packet: %v\n", err) } fmt.Printf("received packet: %s\n", string(buf[:n])) }Determining Package: The package/library used in the above code examples is "net" which is a part of the standard Go library.