2017-05-05 46 views
3

我嘗試使用UDP通過本地網絡傳輸大量數據,並使用QT作爲Socket訪問的框架。發送簡單消息到目前爲止不是問題。 但是,我沒有(完全)理解如何處理包的分割以及由誰來完成。UDP拆分/合併。哪一層處理它? (QT Networking)

所以QT指出:

發送數據包大於512個字節是一般disadvised,因爲即使它們被成功發送,他們很可能要由IP層在他們到達最終目的地之前支離破碎。

因此我實現了我自己的小協議來處理大數據的拆分和合並。具有更大的尺寸大於512個字節(在10kBytes的順序)播放的時候,我遇到了下面的代碼片段從Wireshark的:

"17","0.145050","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=0, ID=3a47) [Reassembled in #23]" 
"18","0.145051","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=1480, ID=3a47) [Reassembled in #23]" 
"19","0.145051","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=2960, ID=3a47) [Reassembled in #23]" 
"20","0.145051","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=4440, ID=3a47) [Reassembled in #23]" 
"21","0.145052","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=5920, ID=3a47) [Reassembled in #23]" 
"22","0.145052","192.168.2.111","192.168.2.222","IPv4","1514","Fragmented IP protocol (proto=UDP 17, off=7400, ID=3a47) [Reassembled in #23]" 
"23","0.145052","192.168.2.111","192.168.2.222","UDP","1186","63230 > 8007 Len=10024" 

,並從我得到一個數據報在QT。 對我來說,似乎IP層已經在分解/合併我的(太大)UDP數據包了。 所以:

  1. 爲什麼建議我自己拆分UDP數據?
  2. 「誰」處理IP層? (QT,Windows,網絡硬件?)
  3. 我假設在UDP套接字中有讀寫緩衝區產生的第二個限制,我可以在哪裏檢查?

回答

3

QT的狀態是無意義的。即使數據報在通過互聯網的途中分散,他們也會在目的地重新發布。他們對這個正在IP層上進行正確的,所以沒有什麼對你的應用程序擔心,除非你打算打破了64k的最大數據包大小(64K - Wikipedia on UDP

至於你的問題:

  1. 明顯錯誤。忽視。
  2. IP層由IP堆棧處理,通常在內核級別
  3. 「第二限制」由IP協議(在你的情況下爲v4)定義,它定義長度字段爲16位,使得最大數據報大小爲64k (RFC 791)

但是,如果你打算做的是以可靠的方式傳輸大塊數據,你應該使用TCP而不是UDP。讓TCP處理這些事情而不是你的應用程序。