我最近看了Richards Stevens写的“UNIX网络编程,Vol. 1”,我发现除了TCP和UDP之外还有第三个传输层标准:SCTP。

概要:SCTP是一种传输级协议,它像UDP一样是消息驱动的,但像TCP一样可靠。下面是来自IBM DeveloperWorks的简短介绍。

老实说,我以前从未听说过SCTP。我不记得在任何网络书籍中读到过它,也不记得在我上的课上听说过它。阅读其他提到SCTP的stackoverflow问题表明,我并不是唯一一个缺乏这种知识的人。

为什么SCTP如此不为人知?为什么不怎么使用呢?


当前回答

它可能不为人所知,但也不是没有被使用过。最近,IETF发布了一份关于使用SCTP作为HTTP传输层协议的草案。

其他回答

关于商业路由器被破坏或缺乏SCTP支持的所有评论,问题是带有NAT的SCTP仍处于IETF的草案形式。所以他们没有RFC规范来实现它。

https://datatracker.ietf.org/doc/html/draft-ietf-behave-sctpnat-09

Sctp诞生得太晚了,对于很多情况,TCP已经足够了。

此外,据我所知,它的大部分使用是在电信领域。

我们中的许多人很快就会使用SCTP,因为WebRTC数据通道使用它在UDP之上创建一个类似tcp的可靠层——SCTP over DTLS over UDP: https://datatracker.ietf.org/doc/html/draft-ietf-rtcweb-data-channel-13#section-6

SCTP不是很为人所知,也不是经常使用/部署,因为:

Widespread: Not widely integrated in TCP/IP stacks (in 2013: still missing natively in latest Mac OSX and Windows. 2020 update: still not in Windows nor Mac OS X) Libraries: Few high level bindings in easy to use languages (Disclaimer: i'm maintainer of pysctp, SCTP easy stack support for Python) NAT: Doesn't cross NAT very well/at all (less than 1% internet home & enterprise routers do NAT on SCTP). Popularity: No general public app use it Programming paradigm: it changed a bit: it's still a socket, but you can connect many hosts to many hosts (multihoming), datagram is ordered and reliable, erc... Complexity: SCTP stack is complex to implement (due to above) Competition: Multipath TCP is coming and should address multihoming needs / capabilities so people refrain from implementing SCTP if possible, waiting for MTCP Niche: Needs SCTP fills are very peculiar (ordered reliable datagrams, multistream) and not needed by much applications Security: SCTP evades security controls (some firewalls, most IDSes, all DLPs, does not appear on netstat except CentOS/Redhat/Fedora...) Audit-ability: Something like 3 companies in the world routinely do audits of SCTP security (Disclaimer: I work in one of them) Learning curve: Not much toolchain to play with SCTP (check the excellent withsctp that combines nicely with netcat or use socat, 2020 edit: nmap supports it for a few years now ) Under the hood: Used mostly in telecom and everytime you send SMS, start surfing the net on your mobile or make phone calls, you're often triggering messages that flow over SCTP (SIGTRAN/SS7 with GSM/UMTS, Diameter with LTE/IMS/RCS, S1AP/X2AP with LTE), so you actually use it a lot but you never know about it ;-) 2020 edit: it's being removed from the core 5G network (no more Diameter, HTTP/2 instead) and will be only used in the 5G radio access network between antennas and core.

SCTP需要在应用程序中进行更多的设计,以便更好地利用它。它比TCP有更多的选择,类似socket的API是后来才出现的,而且它很年轻。然而,我认为大多数花时间理解它的人(并且知道TCP的缺点)都很欣赏它——这是一个设计良好的协议,建立在我们对TCP和UDP大约30年的知识之上。

其中一个需要思考的方面是流。流提供了(通常,我认为您可以关闭它)它们之间的顺序保证(很像TCP连接),但是每个SCTP连接可以有多个流。如果您的应用程序的数据可以通过多个流发送,那么您就可以避免由于一个错误放置的数据包而导致的接收端阻塞。有效地,不同的对话可以在同一个连接上进行,而不会相互影响。

另一个有用的附加功能是多归属支持——一个连接可以跨两端的多个接口,它可以处理故障。您可以在TCP中模拟这一点,但是是在应用层。

正确的链接心跳是任何使用TCP进行非瞬态连接的应用程序实现的第一件事,它是免费的。

我个人对SCTP的总结是,它没有做任何其他方式(在TCP或UDP中)在大量应用程序支持下不能做的事情。它所提供的是不必自己(糟糕地)实现代码的能力。

供参考,SCTP是强制支持的直径(cf RADIUS下一代)。参见RFC 3588

   Diameter clients MUST support either TCP or SCTP, while agents and
   servers MUST support both.  Future versions of this specification MAY
   mandate that clients support SCTP.