本文主要是介绍嵌入式学习day34 网络,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
TCP包头:
1.序号:发送端发送数据包的编号
2.确认号:已经确认接收到的数据的编号(只有当ACK为1时,确认号才有用)
TCP为什么安全可靠:
1.在通信前建立三次握手连接
SYN
SYN+ACK
ACK
2.在通信过程中通过序列号和确认号保障数据传输的完整性
本次发送序列号:上次收到的确认号
本次发送确认号:上次接收到的序列号 + 实际接收的数据长度
在传输过程中使用滑动窗口实现流量控制
3.在通信结束时使用四次挥手结束连接保障数据传输的完整性
UDP和TCP的区别:
1.UDP和TCP都是传输层的协议
2.UDP实现机制简单、资源开销小、不安全不可靠
3.TCP实现机制复杂、资源开销大、安全可靠
4.UDP是无连接的、TCP有连接的、UDP是以数据包形式传输、TCP是以流的方式传输
TCP三次握手,四次挥手图示:
TCP包头图示:(图片源于网络)
传输
URL:http://api.k780.com/?app=weather.today&weaid=西安&appkey=44923&sign=c9815919d111da6c2c9ca64a304f640b&format=json
注意:
appkey:换成自己的APPKey
sign:换成自己的sign标识
HTTP:
1.URL
<协议>://<主机>:<端口>/<路径>
协议:HTTP 80 TCP
HTTPS 443 TCP
主机: 域名 -> 域名解析服务器 -> IP地址
端口: 可以省略, HTTP 80
HTTPS 443
路径: 想要获得对应的资源
2.HTTP交互过程:
1.建立TCP连接
2.发送HTTP请求报文
3.回复HTTP响应报文
4.关闭TCP连接
网站IP:103.205.5.249:80
请求报文格式:
GET /?app=weather.today&weaid=%E8%A5%BF%E5%AE%89&appkey=44923&sign=c9815919d111da6c2c9ca64a304f640b&format=json HTTP/1.1\r\n
Host: api.k780.com\r\n
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/113.0\r\n
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n
Accept-Language: en-US,en;q=0.5\r\n
Connection: keep-alive\r\n\r\n
响应报文格式:
HTTP/1.1 200 OK\r\n
Server: nginx\r\n
Date: Fri, 08 Mar 2024 06:33:44 GMT\r\n
Content-Type: application/json; charset=utf-8;\r\n
Transfer-Encoding: chunked\r\n
Connection: keep-alive\r\n
Access-Control-Allow-Origin: *\r\n
\r\n
{"success":"1","result":{"weaid":"316","days":"2024-03-08","week":".........","cityno":"xian","citynm":"......","cityid":"101110101","temperature":"13.../0...","temperature_curr":"12...","humidity":"29%","aqi":"65","weather":"............","weather_curr":"...","weather_icon":"http://api.k780.com/upload/weather/d/0.gif","weather_icon1":"","wind":"......","winp":"2...","temp_high":"13","temp_low":"0","temp_curr":"12","humi_high":"0","humi_low":"0","weatid":"1","weatid1":"","windid":"4","winpid":"2","weather_iconid":"0"}}\r\n
这篇关于嵌入式学习day34 网络的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!