马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
<p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; font-weight: 700;">UDP 协议简介</span></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">UDP是一个简单的面向数据报的传输层协议:进程的每个输出操作都正好产生一个 UDP数据报,并组装成一份待发送的IP数据报。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">这与面向流字符的协议不同,如 TCP,应用程序产生的全体数据与真正发送的单个IP数 据报可能没有什么联系。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">UDP不提供可靠性:它把应用程序传给IP层的数据发送出去,但是并不保证它们能到达目的地。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">应用程序必须关心IP数据报的长度。如果它超过网络的 MTU,那么就要对IP数 据报进行分片。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">UDP/IP 的报文结构如下图所示:</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462721755972966554775.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="528" height="193" src="/upload/image/20231115/1700026079238629.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462723815375394997058.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="528" height="189" src="/upload/image/20231115/1700026079782505.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● 端口号表示发送进程和接收进程。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● TCP端口号与UDP端口号是相互独立的。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● 尽管相互独立,如果TCP和UDP同时提供某种知名服务,两个协议通常选择相同的端口号。这纯粹是为了使用方便,而不是协议本身的要求。(DNS)</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● UDP长度字段指的是UDP首部和UDP数据的字节长度。该字段的最小值为 8字节。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462731999630258393789.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="528" height="311" src="/upload/image/20231115/1700026080631143.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● UDP检验和是覆盖UDP首部和UDP数据。IP首部的校验和,它只覆盖IP的首部</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● UDP的检验和是可选的,而TCP的检验和是必需的。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● IP计算校验和和UDP计算校验和之间存在不同的地方。首先, UDP数据报的长度可以为 奇数字节,但是检验和算法是把若干个 16 bit字相加。解决方法是必要时在最后增加填充字节 0,这只是为了检验和的计算(也就是说,可能增加的填充字节不被传送)。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">● UDP数据报和TCP段都包含一个1 2字节长的伪首部,它是为了计算检验和而设置的。伪首部包含IP首部一些字段。其目的是让UDP两次检查数据是否已经正确到达目的地 (例如,IP没有接收地址不是本主机的数据报,以及 IP没有把应传给另一高层的数据报传给 UDP)。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">上图中,我们特地举了一个奇数长度的数据报例子,因而在计算检验和时需要加上填 充字节。注意,UDP数据报的长度在检验和计算过程中出现两次。 如果检验和的计算结果为 0,则存入的值为全1(65535),这在二进制反码计算中是等效的。如果传送的检验和为0,说明发送端没有计算检验和。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">如果发送端没有计算检验和而接收端检测到检验和有差错,那么 UDP数据报就要被悄悄 地丢弃。不产生任何差错报文(当 IP层检测到IP首部检验和有差错时也这样做)。 UDP检验和是一个端到端的检验和。它由发送端计算,然后由接收端验证。其目的是为了发现UDP首部和数据在发送端到接收端之间发生的任何改动。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; font-weight: 700;">Python 实现UDP协议</span></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">Python利用Socket模块来实现UDP协议。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; font-weight: 700;">UDP Socket Server的示例程序:</span></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462740038700976332858.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="418" height="385" src="/upload/image/20231115/1700026080638557.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; font-weight: 700;">UDP Socket Client的示例程序:</span></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462742373476945030913.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="471" height="308" src="/upload/image/20231115/1700026081805647.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; font-weight: 700;">运行UDP Socket Client程序并开启抓包</span></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462746054182372189489.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="528" height="434" src="/upload/image/20231115/1700026081195871.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462746716689302798847.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="528" height="274" src="/upload/image/20231115/1700026082929391.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">从抓取到的数据包可以看到:</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">1、没有会话建立的过程。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">2、数据并没有确认。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">3、应用的每一次操作,网络上对应一个数据包。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">4、服务器端没有开启侦听对应的UDP端口,就会自动发送ICMP的差错报文给发送端。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">对发送UDP报(红色框中的1号)和响应报(红色框中的2号)进行详细分析如下图:</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462749478581592792588.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="528" height="290" src="/upload/image/20231115/1700026082252231.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; font-weight: 700;">两种Python 发送UDP数据方式</span></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">方式一:Socket发送</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462753739513222974498.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="409" height="214" src="/upload/image/20231115/1700026082473185.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">方式二:Scapy sr1发送</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><br/></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><a target="_blank" href="https://www.ad.siemens.com.cn/club/bbs/upload/image/20231103/6383462758173254863598445.png" style="box-sizing: border-box; padding: 0px; margin: 0px; color: rgb(50, 50, 50); outline: 0px; background-color: transparent; cursor: pointer; border: none; text-decoration-line: none !important;"><img width="528" height="161" src="/upload/image/20231115/1700026083728285.png" style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; border: 0px; vertical-align: middle;"/></a></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, "Noto Sans CJK SC", "WenQuanYi Micro Hei", Arial, sans-serif; padding: 0px; margin: 0px; font-weight: 700;">两种方式的差别:</span></p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">方式一是把UDP数据转交给驱动程序处理,数据长度超了MTU后,数据的分片由驱动来自动实现,劣势是不能指定发送的网卡接口。</p><p style="box-sizing: border-box; font-family: "Noto Sans SC", "Microsoft YaHei", ���ź�, -apple-system, BlinkMacSystemFont, "segoe ui", Roboto; padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(0, 0, 40); text-align: justify; font-size: 14px; line-height: 26px; text-wrap: wrap; background-color: rgb(255, 255, 255);">方式二是通过Scapy发送数据,数据不转交驱动程序,所以有分片需求时,不能被自动实现分片功能,优势是可以选择发送的接口网卡。<br/>原文地址</p><p><a href="https://www.ad.siemens.com.cn/club/bbs/PostStory_1855429_109_4.html#anch">网络协议详解04—UDP协议-技术论坛-工业支持中心-西门子中国 (siemens.com.cn)</a></p> |