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
+39k Golang : How to iterate over a []string(array)
+47.8k Golang : Convert int to byte array([]byte)
+17.9k Golang : Simple client server example
+25.3k Golang : Convert uint value to string type
+5.8k Golang : List all packages and search for certain package
+13.1k Golang : List objects in AWS S3 bucket
+14.4k Golang : How to filter a map's elements for faster lookup
+6.8k Golang : Calculate pivot points for a cross
+4.1k Javascript : Empty an array example
+4.7k Unix/Linux : How to pipe/save output of a command to file?
+5.4k Javascript : How to loop over and parse JSON data?
+6.6k Golang : Totalize or add-up an array or slice example