gobyexample/xx-tcp-client.go
Mark McGranaghan 1c0a6d298f more
2012-09-16 18:54:32 -07:00

31 lines
439 B
Go

package main
import ("fmt"; "net")
func client() {
}
func main() {
c, err := net.Dial("tcp", "127.0.0.1:5000")
if err != nil {
panic(err)
}
msg := "Hello World"
fmt.Println("Sending: ", msg)
_, err = c.Write([]byte(msg))
if err != nil {
panic(err)
}
buf := make([]byte, 1024)
_, err = c.Read(buf)
if err != nil {
panic(err)
} else {
fmt.Println("Received:", string(buf))
c.Close()
}
}