-
SSM指定源组播与ASM任意源组播基础概念
ASM-任意源组播,(IGMP-V2协议)
在这种模型下,任何发送方可以发送给任何组。在路由器角度上看,只要接收方“注册”了自己属于组播,任何发送方(任何源)的数据都会分到接收方。
SSM-指定源组播,(IGMP-V3协议)
接收方在“注册”自己加入组的同时,还会告诉路由器只接受某几个发送方(指定源),包括一个组地址和一个源IP地址。在这种模型下,其实任何发送方还是可以发送给任何组的。只是路由器会根据注册信息里的只把“合法源”的数据给到接收方。
从网络配置人员的角度看SSM避免了ASM部署的复杂性,从程序员角度看,SSM要比ASM麻烦一点点就是在加入组播的“注册”过程中,要把“源”的IP信息加进去。可能是我孤陋寡闻可能是Qt真的没考虑这个SSM的应用,至少从Qt4.8.X直到用的Qt5.9.X的Qt封装的QUdpSocket感觉没有支持的特别到位。
最新消息是:即使在 Qt 6.8 下实现指定源组播,仍需像之前版本一样,手动使用 QUdpSocket 的 socketDescriptor() 函数获取底层套接字描述符,然后通过 setsockopt 函数设置加入指定源组播选项
-
.pro文件
除了network,windows还要多包一个LIBS += -lWs2_32
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = D2dRecv
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
win32 {
LIBS += -lWs2_32
}
unix{
}
SOURCES += \
main.cpp \
dialog.cpp
HEADERS += \
dialog.h
FORMS += \
dialog.ui
-
直接上代码
核心是用QUdpSocket的socketDescrip