conn, err := net.Dial("tcp", "localhost:8080") if err != nil { log.Fatal(err) } defer conn.Close() message := []byte("Hello, server!") conn.Write(message)
conn, err := listener.Accept() if err != nil { log.Fatal(err) } defer conn.Close() messages := [][]byte{[]byte("Message 1"), []byte("Message 2"), []byte("Message 3")} for _, message := range messages { conn.Write(message) }This code accepts a connection from a client and sends multiple messages "Message 1", "Message 2", and "Message 3" to the client using TCPConn Write. The package library used in these examples is "net".