go-examples/tcpclient/main.go

26 lines
334 B
Go
Raw Normal View History

2017-07-09 13:04:44 +00:00
package main
import "fmt"
import "io/ioutil"
import "net"
import "os"
func main() {
addr := "localhost:9000"
if len(os.Args) == 2 {
addr = os.Args[1]
}
d, err := net.Dial("tcp", addr)
if err != nil {
panic(err)
}
defer d.Close()
bs, err := ioutil.ReadAll(d)
if err != nil {
panic(err)
}
fmt.Println(string(bs))
}