http_server complete,but have not reviewed yet

main
Your Name 2024-07-12 00:41:03 +08:00
parent a5b20d8c4b
commit 12a0c78983
3 changed files with 39 additions and 0 deletions

9
HTTP/fronted.html Normal file
View File

@ -0,0 +1,9 @@
<h1 style="color:red">hello world</h1>
<a href="https://www.baidu.com">跳转百度</a>
<img id="i1" src="https://img1.baidu.com/it/u=3518673092,2032183538&fm=253&fmt=auto&app=138&f=JPEG?w=781&h=500" width="400"/>
<button id="b1">点我</button>
<script>
document.getElementById("b1").onclick=function (){
document.getElementById("i1").src="https://p8.itc.cn/q_70/images01/20220316/60665900b6224f308abd93e838dd444f.png"
}
</script>

24
HTTP/http_server.go Normal file
View File

@ -0,0 +1,24 @@
package main
import (
"fmt"
"net/http"
"os"
)
func f1(w http.ResponseWriter, r *http.Request) {
b, err := os.ReadFile("./HTTP/fronted.html")
if err != nil {
w.Write([]byte(fmt.Sprintf("%v", err)))
return
}
w.Write(b)
}
// http server
func main() {
http.HandleFunc("/web", f1)
http.ListenAndServe("127.0.0.1:9090", nil)
}

View File

@ -32,5 +32,11 @@ TCP服务端程序的处理流程
3.关闭链接 3.关闭链接
TCP粘包 TCP粘包
主要原因就是tcp数据传递模式是流模式在保持长连接的时候可以进行多次的收和发。
“粘包"可发生在发送端也可发生在接收端:
由Nagle算法造成的发送端的粘包Nagle算法是一种改善网络传输效率的算法。简单来说就是当我们提交一段数据给TCP发送时TCP并不立刻发送此段数据而是等待一小段时间看看在等待期间是否还有要发送的数据若有则会一次把这两段数据发送出去。
接收端接收不及时造成的接收端粘包TCP会把接收到的数据存在自己的缓冲区中然后通知应用层取数据。当应用层由于某些原因不能及时的把TCP的数据取出来就会造成TCP缓冲区中存放了几段数据。
引申知识点: 引申知识点:
大端和小端{https://zhuanlan.zhihu.com/p/680366680} 大端和小端{https://zhuanlan.zhihu.com/p/680366680}