Golang net.IPConn.SetDeadline(), SetReadDeadline() and SetReadBuffer() functions example
package net
Golang net.IPConn.SetDeadline(), SetReadDeadline() and SetReadBuffer() functions usage example
package main
import (
"fmt"
"net"
"time"
)
func main() {
// replace x with your target IP address
raddr := &net.IPAddr{IP: net.IPv4(x, x, x, x).To4()}
laddr := &net.IPAddr{IP: net.IPv4(x, x, x, x)}
ipconn, err := net.DialIP("ip:tcp", laddr, raddr)
if err != nil {
fmt.Println("Error: ", err)
} else {
fmt.Println(ipconn)
}
defer ipconn.Close()
// the same can be applied to SetWriteDeadline() and SetWriteBuffer() functions as well
t := time.Now()
ipconn.SetDeadline(t.Add(100 * time.Millisecond))
ipconn.SetReadDeadline(t.Add(250 * time.Millisecond))
//buffer := make([]byte, 4096)
err := ipconn.SetReadBuffer(4096)
if err != nil {
fmt.Println("Error: ", err)
}
}
References :
http://golang.org/pkg/net/#IPConn.SetDeadline
Advertisement
Something interesting
Tutorials
+5.6k Golang : Detect words using using consecutive letters in a given string
+12.9k Golang : Convert IPv4 address to packed 32-bit binary format
+7.1k Golang : Get environment variable
+6k Golang : Function as an argument type example
+8.6k Golang : Set or add headers for many or different handlers
+5.3k Python : Convert(cast) string to bytes example
+6.4k Golang : Break string into a slice of characters example
+12.3k Golang : Display list of countries and ISO codes
+7.5k Golang : Gorrila set route name and get the current route name
+19.3k Golang : Calculate entire request body length during run time
+29.4k Golang : JQuery AJAX post data to server and send data back to client example