package main import ( "fmt" "net" ) func main() { addr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:8080") if err != nil { fmt.Println(err) return } fmt.Println("TCP Address: ", addr) fmt.Println("IP Address: ", addr.IP) }
package main import ( "fmt" "net" ) func main() { conn, err := net.Dial("tcp", "127.0.0.1:8080") if err != nil { fmt.Println(err) return } defer conn.Close() fmt.Fprintf(conn, "Hello, World!") }In this example, we are using the `Dial` function to establish a TCP connection to a server running on the local host on port 8080. We then send a message to the server using the `fmt.Fprintf` function. The `defer conn.Close()` statement ensures that the connection is closed after the message is sent. These examples use the net package library in Go.