Ubuntu的Socket编程:数据包TX和RX之间的重新包装 [英] Ubuntu Socket programming : Packets are repackaged between TX and RX
问题描述
我有两个Ubuntu的14.04电脑。一个用作服务器和另一个被用作客户端。客户端安装一个TCP连接到服务器,发送一些数据包传回。这里的服务器上的code:
I have 2 Ubuntu 14.04 PCs. One is used as a server and the other one is used as a client. The client setup a TCP connection to the server which sends some packets back. Here's the code on the server:
发(SD,PKT,pkt_len,MSG_NOSIGNAL);
send(sd, pkt, pkt_len, MSG_NOSIGNAL);
在客户端的code也很简单:
The code on the client side is also very simple:
阅读(SD,BUF,buf_size);
read(sd, buf, buf_size);
如果服务器上的传输是隔开的,我看不出有什么问题。但是,如果服务器是做快速传输,那么事情看起来很难看。下面是当服务器发送8个数据包背到后面的一个例子。
If the transmissions on the server is spaced out, I don't see any issue. However, if server is doing rapid transmissions, then thing looks ugly. Here's an example when the server is sending 8 packets back-to-back.
服务器code显示了这8个数据包的大小为:752(字节),713,713,713,396,398,396,396
The server code shows the size of these 8 packets are: 752 (bytes), 713, 713, 713, 396, 398, 396, 396
tcpdump的服务器上捕获4 TX数据包:752(字节),1398,1398,929
tcpdump on the server captures 4 TX packets: 752 (bytes), 1398, 1398, 929
在客户端上的tcpdump捕获3 RX数据包:752(字节),2796,929
tcpdump on the client captures 3 RX packets: 752 (bytes), 2796, 929
客户端code显示它收到3548分别字节,字节929,只有2包。
The client code shows it receives only 2 packets with 3548 bytes and 929 bytes, respectively.
所以,你可以看到所有服务器发送的字节数由客户端接收。但是,数据包在传输路径中的各个点相结合。我想这是因为TSO,GSO,GRO等。但是,不应该这些优化重新组装数据包回当数据包传送到接收应用程序的正确形式?
So you can see all the bytes sent by the server are received by the client. However, packets are combined at various points in the transmission path. I guess this is due to TSO, GSO, GRO, etc. However, shouldn't these optimizations re-assemble the packets back to the correct form when the packets are delivered to the receiving application?
我如何解决此问题得到什么?
How do I get around this issue?
推荐答案
TCP经过精心设计,不仅许可证,但实现你看到什么。这是一个字节流协议。如果你想要的信息,你必须通过自己的叠加应用协议实现它们。
TCP is carefully designed to not only permit but implement exactly what you're seeing. It is a byte-stream protocol. If you want messages you have to implement them yourself via a superimposed application protocol.
这篇关于Ubuntu的Socket编程:数据包TX和RX之间的重新包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!