Created
March 26, 2022 12:43
-
-
Save Chion82/c6955e2c06616e53af485553eef66a6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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