Ai
681 Star 7.8K Fork 3.4K

陌溪/LearningNotes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 814 Bytes
一键复制 编辑 原始数据 按行查看 历史
陌溪 提交于 2020-09-17 18:38 +08:00 . docs:增加Gin框架学习笔记和代码
package main
import (
"bufio"
"fmt"
"net"
"os"
)
func getInput() string {
//使用os.Stdin开启输入流
//函数原型 func NewReader(rd io.Reader) *Reader
//NewReader创建一个具有默认大小缓冲、从r读取的*Reader 结构见官方文档
in := bufio.NewReader(os.Stdin)
//in.ReadLine函数具有三个返回值 []byte bool error
//分别为读取到的信息 是否数据太长导致缓冲区溢出 是否读取失败
str, _, err := in.ReadLine()
if err != nil {
return err.Error()
}
return string(str)
}
// tcp client
func main() {
// 与server端建立连接
conn, err := net.Dial("tcp", "127.0.0.1:20000")
if err != nil {
fmt.Println("dial 127.0.0.1:20000 failed, err:", err)
return
}
// 发送数据
conn.Write([]byte(getInput()))
// 关闭流
defer conn.Close()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/moxi159753/LearningNotes.git
git@gitee.com:moxi159753/LearningNotes.git
moxi159753
LearningNotes
LearningNotes
master

搜索帮助