package main import ( "net" ) func main() { conn, _ := net.Dial("tcp", "example.com:80") data := []byte("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n") conn.Write(data) }
package main import ( "net" ) func main() { conn, _ := net.ListenPacket("udp", "127.0.0.1:8000") data := []byte{0x01, 0x02, 0x03, 0x04} conn.WriteTo(data, &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 8000}) }This example listens for incoming UDP packets on port 8000 and sends a binary data packet to the same port. In both examples, the net package is used to create network connections and send data over them.