gobyexample/088-tcp-client.go
Mark McGranaghan 354a9d862f reorder
2012-09-21 07:54:20 -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()
}
}