Skip to content

Instantly share code, notes, and snippets.

@Chion82
Created March 26, 2022 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chion82/c6955e2c06616e53af485553eef66a6e to your computer and use it in GitHub Desktop.
Save Chion82/c6955e2c06616e53af485553eef66a6e to your computer and use it in GitHub Desktop.
package main
import (
"net"
"os"
"syscall"
"time"
)
func main() {
strEcho := "Halo"
servAddr := "localhost:6666"
dialer := net.Dialer{
Timeout: time.Second * 10,
}
dialer.Control = func(network, address string, c syscall.RawConn) error {
var err error
c.Control(func(fd uintptr) {
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_TOS, 0x80)
})
return err
}
conn, err := dialer.Dial("tcp", servAddr)
if err != nil {
println("Dial failed:", err.Error())
os.Exit(1)
}
_, err = conn.Write([]byte(strEcho))
if err != nil {
println("Write to server failed:", err.Error())
os.Exit(1)
}
println("write to server = ", strEcho)
reply := make([]byte, 1024)
_, err = conn.Read(reply)
if err != nil {
println("Write to server failed:", err.Error())
os.Exit(1)
}
println("reply from server=", string(reply))
conn.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment