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
+17.8k Golang : Iterate linked list example
+6.6k Golang : How to determine if request or crawl is from Google robots
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+11.5k CodeIgniter : Import Linkedin data
+33.8k Golang : convert(cast) bytes to string
+14k Golang : Compress and decompress file with compress/flate example
+16.4k Golang : Convert slice to array
+11.2k CodeIgniter : How to check if a session exist in PHP?
+11.7k Golang : Calculations using complex numbers example
+6.6k Golang : Totalize or add-up an array or slice example
+6.1k Java : Human readable password generator
+36.7k Golang : Display float in 2 decimal points and rounding up or down