go-examples/tcpclient/main.go
2017-07-09 15:04:44 +02:00

26 lines
334 B
Go

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))
}