c - SCTP 有序消息传递

标签 c packet sctp partial-ordering

是否可以强制 SCTP 发送完全有序的所有数据?

让我们做这个实验:

1) 拿这个 SCTP-discard-server而这个 SCTP-client .

2)让客户端多次计数到100,每次分别向服务器发送一个字节。

for(long i=0; i< 1000000000; i++){
    char temp = (char)(i%100) + 1;
    usrsctp_sendv(
        sock, (void *)&temp, 1,
        NULL, 0, NULL, 0, SCTP_SENDV_NOINFO, 0
    );
}

3)让服务器沿同样的方式计数,并将其数量与接收到的数量进行比较。
printf("%d %d\n", (int)buffer[0], (int)(test));
if ((int)test != (int)buffer[0]) break;

几秒钟后:
66 66
67 67
68 68
69 69
51 70

瞧!

我用 $ gcc discard_server.c -Wall -lusrsctp 编译了这个在我的 Ubuntu 18.04 机器上使用 gcc7.3.0。是的,我已经尝试通过 SCTP_NODELAY 禁用各种 nagel 算法。 .

我错过了什么?提前感谢您的任何提示。

最佳答案

您可能遗漏的是 SCTP 不保证关联内的顺序传递。只有在流中才能保证顺序交付。
RFC 4960 chapter 1.5.2说:

Internally, SCTP assigns a Stream Sequence Number to each message passed to it by the SCTP user. On the receiving side, SCTP ensures that messages are delivered to the SCTP user in sequence within a given stream. However, while one stream may be blocked waiting for the next in-sequence user message, delivery from other streams may proceed.


我猜您配置了不止一个流,并且您使用的实现在流之间分配负载。这应该很容易通过wireshark跟踪确认。
如果您携带消息顺序,您应该在发送数据时指定流 ID,并在数据到达时检查流 ID。

关于c - SCTP 有序消息传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54065852/

相关文章:

c - 在 C 中实现链表时,谁负责释放值?

.net - 如何监听任何端口上的广播数据包?

java - 数据包被 netty 损坏

linux - netinet/sctp.h : No such file or directory

c - 如何使用包含好的 pcap 结构

c - 使用 C sscanf 解析目录路径中的数字

c - super 奇怪的问题触发 "Segmentation Fault"

java - 发送数据报包时,数据包的数据是重复的。 (java)

linux - 我在 Redhat 上安装 libsctp 时遇到问题

TCP 和 SCTP 上的 Linux 内核