package main
import (
"net"
"time"
)
func main() {
addr := "127.0.0.1:80"
netAddr := &net.TCPAddr{Port: 6666}
d := net.Dialer{LocalAddr: netAddr}
cc, err := d.Dial("tcp", addr)
if err != nil {
return
}
for {
cc.Write([]byte("aaa\n"))
time.Sleep(time.Second)
}
}
package main
import (
"fmt"
"net"
"net/http"
"time"
)
func main() {
netAddr := &net.TCPAddr{Port: 6667}
dialer := &net.Dialer{LocalAddr: netAddr}
tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: dialer.DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
c := &http.Client{
Transport: tr,
}
url := "https://www.h2check.org/"
resp, err := c.Get(url)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%+v\n", resp.Header)
fmt.Printf("%s\n", resp.Body)
}
|