Go实战--实现一个简单的tcp服务端和客户端(The way to go)

本文将介绍如何使用Go语言实现一个简单的TCP服务端和客户端。首先讲解了net.Listen的基础知识,然后展示了如何编写server端和client端的代码。通过示例代码`tcp_server.go`和`tcp_client.go`,读者可以了解到Go中创建TCP连接的基本步骤。

生命不止,继续 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一苇渡江694

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值