Skip to content

Instantly share code, notes, and snippets.

@adeekshith
Forked from iwanbk/gist:2295233
Last active January 3, 2025 12:46
Show Gist options
  • Save adeekshith/34c20eb45bebe41f5247 to your computer and use it in GitHub Desktop.
Save adeekshith/34c20eb45bebe41f5247 to your computer and use it in GitHub Desktop.
package main
import (
"net"
"os"
)
func main() {
strEcho := "Halo"
servAddr := "localhost:6666"
tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
if err != nil {
println("ResolveTCPAddr failed:", err.Error())
os.Exit(1)
}
conn, err := net.DialTCP("tcp", nil, tcpAddr)
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()
}
@lockness-Ko
Copy link

Thank you! This helped me so much.

@bartfroklage
Copy link

Thanks it helped me too..
Maybe you can change the text of the line 34 to something like read from server failed.

@SinaKarimi00
Copy link

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment