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
+29.3k Golang : Save map/struct to JSON or XML file
+6.9k Nginx : Password protect a directory/folder
+9.2k Golang : Write multiple lines or divide string into multiple lines
+14.5k How to automatically restart your crashed Golang server
+10k Golang : Get escape characters \u form from unicode characters
+11.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+12.7k Golang : Remove or trim extra comma from CSV
+5.4k Golang : Reclaim memory occupied by make() example
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+5.2k Python : Create Whois client or function example
+16k Golang : Read large file with bufio.Scanner cause token too long error
+6.4k Golang : Break string into a slice of characters example