生命不止,继续 go go go !!!
之前介绍了go为我们提供的net/http包,很方便的创建一些api。
今天就来点实战,写一个简单的tcp的服务端、客户端程序。
按照国际惯例,还是先介绍一点点基础知识。
* net.Listen*
Listen announces on the local network address laddr. The network net must be a stream-oriented network: “tcp”, “tcp4”, “tcp6”, “unix” or “unixpacket”. For TCP and UDP, the syntax of laddr is “host:port”, like “127.0.0.1:8080”. If host is omitted, as in “:8080”, Listen listens on all available interfaces instead of just the interface with the given host address. See Dial for more details about address syntax.
Listening on a hostname is not recommended because this creates a socket for at most one of its IP addresses.
func