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文章来源:https://www.toymoban.com/news/detail-838059.html
响应报文格式:
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
文章来源地址https://www.toymoban.com/news/detail-838059.html
到了这里,关于嵌入式学习day34 网络的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!