conn, err := net.Dial("tcp", "example.com:80") if err != nil { log.Fatal(err) } conn.SetReadDeadline(time.Now().Add(5 * time.Second))
conn, err := net.Dial("tcp", "example.com:80") if err != nil { log.Fatal(err) } conn.SetWriteDeadline(time.Now().Add(5 * time.Second)) _, err = conn.Write([]byte("Hello, world!"))This code establishes a TCP connection to "example.com" on port 80 and sets a write deadline of 5 seconds from the current time. If the server is not able to receive the data ("Hello, world!") within 5 seconds, the connection is closed. Both of these examples use the "net" package library in Go.