1 Star 0 Fork 0

mccapp / Gostudydemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
tcp_server.go 550 Bytes
一键复制 编辑 原始数据 按行查看 历史
mccapp 提交于 2018-12-27 18:12 . ...
package main
import (
"bufio"
"fmt"
"net"
"strings"
)
func main() {
fmt.Println("Launching server..")
ln, _ := net.Listen("tcp", "localhost:8081")
conn, _ := ln.Accept()
for {
// will listen for message to process ending in newline (\n)
message, _ := bufio.NewReader(conn).ReadString('\n')
// output message received
fmt.Print("Message Received:", string(message))
// sample process for string received
newmessage := strings.ToUpper(message)
// send new string back to client
conn.Write([]byte(newmessage + "\n"))
}
}
1
https://gitee.com/mccapp/Gostudydemo.git
git@gitee.com:mccapp/Gostudydemo.git
mccapp
Gostudydemo
Gostudydemo
master

搜索帮助