- 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"))
...
}
推薦閱讀
- 微商之道
- 重新定義Spring Cloud實(shí)戰(zhàn)
- 物聯(lián)網(wǎng)安全與深度學(xué)習(xí)技術(shù)
- 走進(jìn)物聯(lián)網(wǎng)
- 網(wǎng)絡(luò)互聯(lián)技術(shù)(實(shí)踐篇)
- 物聯(lián)網(wǎng)技術(shù)與應(yīng)用
- 智慧光網(wǎng)絡(luò):關(guān)鍵技術(shù)、應(yīng)用實(shí)踐和未來(lái)演進(jìn)
- 網(wǎng)絡(luò)基礎(chǔ)與網(wǎng)絡(luò)管理項(xiàng)目化教程
- Building RESTful Web Services with .NET Core
- 區(qū)塊鏈技術(shù)與應(yīng)用:打造分布式商業(yè)新生態(tài)
- Corona SDK Application Design
- 網(wǎng)絡(luò)基本通信約束下的系統(tǒng)性能極限分析與設(shè)計(jì)
- Scala Programming Projects
- VMware vSphere 5.0虛擬化架構(gòu)實(shí)戰(zhàn)指南
- 網(wǎng)絡(luò)是怎樣連接的