Groupsock内部封装了udp套接字,用来实现组播消息群发。
Groupsock在其父类构造函数中,执行setupDatagramSocket函数初始化,创建套接字并绑定端口:
Socket::Socket(UsageEnvironment& env, Port port, int family)
: fEnv(DefaultUsageEnvironment != NULL ? *DefaultUsageEnvironment : env),
fPort(port), fFamily(family) {
fSocketNum = setupDatagramSocket(fEnv, port, family);
}
int setupDatagramSocket(UsageEnvironment& env, Port port, int domain) {
……
int newSocket = createSocket(domain, SOCK_DGRAM);
……
if (domain == AF_INET) {
// Note: Windoze requires binding, even if the port number is 0
ipv4AddressBits addr = INADDR_ANY;
if (port.num() != 0 || ReceivingInterfaceAddr != INADDR_ANY) {
if (port.num() == 0) addr = ReceivingInterfaceAddr;
MAKE_SOCKADDR_IN(name, addr, port.num());
if (bind(newSocket, (struct sockaddr*)&name, sizeof name) != 0) {
char tmpBuffer[100]
|