美文网首页
SCTP通信中的stream和ssn

SCTP通信中的stream和ssn

作者: EVANMORE | 来源:发表于2018-01-08 21:56 被阅读20次

1. 指定在某个stream上发送消息

在调用sctp_sendmsg函数发送消息的时候,我们可以设置stream ID,

sctp_sendmsg(sock_op->socket_fd(), message, MAX_BUFFER, 
                    (sockaddr *)&servaddr, sizeof(servaddr), 0, 0, stream, 0, 0);

倒数第三个参数就是stream,我们可以指定在某个stream发送消息,

  • 一个SCTP association包含多个stream,默认情况下最大有10个stream;
  • 每个stream上的传输相互独立,比如说stream 0的传输出现阻塞了,不会影响stream 1上的消息传输
  • 每个stream上传输的数据包都有序列号

2. 设置最大最小stream数

可以通过设置socket的属性来设置最大的stream数,

sctp_initmsg initmsg;
sctp_event_subscribe evnts;  
    
// Specify that a maximum of 5 streams will be available per socket 
memset( &initmsg, 0, sizeof(initmsg) );
initmsg.sinit_num_ostreams = 5;
initmsg.sinit_max_instreams = 5;
initmsg.sinit_max_attempts = 4;
if(0 != setsockopt( sock_fd, IPPROTO_SCTP, SCTP_INITMSG,
                     &initmsg, sizeof(initmsg) ))

3. 同一个stream上数据包的序列

发送端每一个消息发送五次,都在同一个stream 1上发送,

printf("[Client]: Input message content!\n");
std::cin >> message ;
for(int i = 0; i < 5; i++)
{
    std::string newMsg = std::move(message + (std::to_string(i)));
    
    printf("[Client]: Send message: %s\n", newMsg.c_str()); 

    sctp_sendmsg(sock_op->socket_fd(), newMsg.c_str(), MAX_BUFFER, 
            (sockaddr *)&servaddr, sizeof(servaddr), 0, 0, stream, 0, 0);
}

第一次发送5个‘hello’,Client端打印如下,

[Client]: Send message: hello0
[Client]: Send message: hello1
[Client]: Send message: hello2
[Client]: Send message: hello3
[Client]: Send message: hello4

我们再来看一下Sever端的接收情况,同时把每个消息的ssn打印出来,

====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('hello0') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(0)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('hello1') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(1)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('hello2') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(2)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('hello3') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(3)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('hello4') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(4)

可以看到,每个消息都有一个自己的序列号,保证消息是有序的,
我们继续再往server端发送5个'world',server端的接收消息依旧是有序的,

 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('world0') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(5)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('world1') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(6)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('world2') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(7)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('world3') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(8)
 ====================================================================
[Server]: Wait for new message or command([0: Exit]; [1: NewMessage])...
[Server]: SCTP message('world4') received from IP/Port(127.0.0.1:47378) on assoc(0x1e) / stream(1), ssn(9)

4. 如果出现丢包的情况

这里我们没法儿模拟丢包的场景,unix网络编程这本书中描述的,如果一个数据包丢失,也就是如果出现NACK

  • 这个stream上的后续的数据包会保存到队列中;
  • 其他的stream不受影响;
  • 丢失的数据包会进行重传,重传成功后,后续队列中的数据包继续按顺序发送;

相关文章

  • SCTP通信中的stream和ssn

    1. 指定在某个stream上发送消息 在调用sctp_sendmsg函数发送消息的时候,我们可以设置stream...

  • SpringCloud-笔记8-Stream消息驱动(Rabbi

    SpringCloud实战9-Stream消息驱动 Spring cloud Stream 的概要介绍 应用程序通...

  • 网络学习九-SCTP

    SCTP是什么? 对于传输层协议很多人都知道tcp,udp,ip协议,而很少人知道sctp(流控制传输协议)这个和...

  • SSN

    标题的有感而发来自看了一下午的射手座,以及昨天一天我们2015年8月份前的聊天信息。 一开始的爱情都是美好的。我一...

  • ssn

    今天没什么好写的,于是我想给大家看一下我之前画的菠萝,我画的很细心,一笔一笔画的从新开始一个圆然后到一步一步的雕刻...

  • SSn

    今天做了一个国旗下的讲话,那时候呢我有一些激动,而且妈妈在后面帮我录视频,我感到如此之光荣,站在这国旗下面光我感觉...

  • ssn

    今天我和他说我今天我去,今天星期五,老师让我在里面做纪律委员。想过一年级卫生室旁边的那一部。 今天晚上还是在了外婆...

  • linux系统下SCTP消息收发函数

    这里介绍的两个SCTP收发消息的函数极大的简化了基于SCTP协议的消息收发,可以更加容易的去使用一些SCTP协议的...

  • 到了美国才知道,原来SSN卡不能直接办理

    懒得读文字?►点我收听:最美声优播报本集出国知识。到了美国才知道,原来SSN卡不能直接办理 美国的身份证SSN卡并...

  • 数据库预习测试题

    查询所有员工的FNAME、LANME、SSN、SEX和SALARY,并分别将SEX和SALARY的列名重命名为“性...

网友评论

      本文标题:SCTP通信中的stream和ssn

      本文链接:https://www.haomeiwen.com/subject/idlinxtx.html