ARTS-S golang goroutines and channels
向tcp服务端发消息
package main
import (
"io"
"log"
"net"
"os"
)
func main() {
conn, err := net.Dial("tcp", "localhost:8080")
defer conn.Close()
if err != nil {
log.Fatal(err)
}
go mustCopy(os.Stdout, conn)
mustCopy(conn, os.Stdin)
}
func mustCopy(dst io.Writer, src io.Reader) {
if _, err := io.Copy(dst, src); err != nil {
log.Printf("mustCopy error:%v", err)
}
}