Skip to content

Instantly share code, notes, and snippets.

@afrolovskiy
Forked from iwanbk/gist:2295233
Last active August 29, 2015 14:16
Show Gist options
  • Save afrolovskiy/06b134b4a0213c945f73 to your computer and use it in GitHub Desktop.
Save afrolovskiy/06b134b4a0213c945f73 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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment