- Go Web Development Cookbook
- Arpit Aggarwal
- 112字
- 2021-08-27 19:01:14
How it works…
Once we run the program, the TCP server will start locally listening on port 8080. Execute an echo command from the command line, as follows:
$ echo -n "Hello to TCP server\n" | nc localhost 8080
This will give us the following response from the server:
Hello to TCP server
Let’s look at the changes we introduced in this recipe to write data to the client. Everything in handleRequest is exactly the same as in the previous recipe except we introduced a new line that writes data as a byte array to the connection, as follows:
func handleRequest(conn net.Conn)
{
...
conn.Write([]byte(message + "\n"))
...
}
推薦閱讀
- EJB 3.1從入門到精通
- 連接未來:從古登堡到谷歌的網(wǎng)絡(luò)革命
- 從區(qū)塊鏈到Web3:構(gòu)建未來互聯(lián)網(wǎng)生態(tài)
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 智慧城市中的移動互聯(lián)網(wǎng)技術(shù)
- 計算機網(wǎng)絡(luò)工程實用教程(第2版)
- 新手易學(xué):新手學(xué)淘寶開店
- 紅藍攻防:構(gòu)建實戰(zhàn)化網(wǎng)絡(luò)安全防御體系
- 無線傳感器網(wǎng)絡(luò)定位技術(shù)
- Implementing NetScaler VPX?
- 物聯(lián)網(wǎng),So Easy!
- Building Microservices with Spring
- SD-WAN 架構(gòu)與技術(shù)
- 云計算、網(wǎng)絡(luò)安全和網(wǎng)絡(luò)盜竊:網(wǎng)絡(luò)世界防盜初學(xué)指南
- Learning IoT with Particle Photon and Electron