组播

组播播出程序中主要的代码: 
        if   ((hSendSocket   =   socket(AF_INET,   SOCK_DGRAM,   0))   ==   INVALID_SOCKET) 
        { 
                sprintf(szPromoteMsg, "socket   failed   with:   %d/n ",   WSAGetLastError()); 
                AfxMessageBox(szPromoteMsg); 

                return   ; 
        } 
        //   Bind   the   socket   to   the   local   interface.   This   is   done   so   
        //   that   we   can   receive   data. 
        local.sin_family   =   AF_INET; 
        local.sin_port       =   htons(m_iPort); 
        local.sin_addr.s_addr   =   m_dwInterface; 

        if   (bind(hSendSocket,   (struct   sockaddr   *)&local,   
                sizeof(local))   ==   SOCKET_ERROR) 
        { 
                sprintf(szPromoteMsg, "bind   failed   with:   %d/n ",   WSAGetLastError()); 
                AfxMessageBox(szPromoteMsg); 

        return   ; 
        } 
        //   Setup   the   im_req   structure   to   indicate   what   group   we   want 
        //   to   join   as   well   as   the   interface 
        // 
        remote.sin_family             =   AF_INET; 
        remote.sin_port                 =   htons(m_iPort); 
        remote.sin_addr.s_addr   =   (m_dwTargetIPAddress); 
        
        mcast.imr_multiaddr.s_addr   =   (m_dwTargetIPAddress); 
        mcast.imr_interface.s_addr   =   m_dwInterface;//±¾µØÒÔÌ«Íø   MAC   µØÖ· 

        if   (setsockopt(hSendSocket,   IPPROTO_IP,   IP_ADD_MEMBERSHIP, 
                (char   *)&mcast,   sizeof(mcast))   ==   SOCKET_ERROR) 
        { 
                sprintf(szPromoteMsg, "setsockopt(IP_ADD_MEMBERSHIP)   failed:   %d/n ",           
                                                            WSAGetLastError()); 
                AfxMessageBox(szPromoteMsg); 

                return   ; 
        } 
        //   Set   the   TTL   to   something   else.   The   default   TTL   is   1. 
        optval   =   8; 
        if   (setsockopt(hSendSocket,   IPPROTO_IP,   IP_MULTICAST_TTL,   
                (char   *)&optval,   sizeof(int))   ==   SOCKET_ERROR) 
        { 
                sprintf(szPromoteMsg, "setsockopt(IP_MULTICAST_TTL)   failed:   %d/n ",   
                WSAGetLastError()); 
                AfxMessageBox(szPromoteMsg); 

                return   ; 
        } 
        //   Disable   the   loopback   if   selected.   Note   that   on   NT4   and   Win95 
        //   you   cannot   disable   it. 
        if   (bLoopBack) 
        { 
                optval   =   0; 
                if   (setsockopt(hSendSocket,   IPPROTO_IP,   IP_MULTICAST_LOOP, 
                        (char   *)&optval,   sizeof(optval))   ==   SOCKET_ERROR) 
                { 
                        sprintf(szPromoteMsg, "setsockopt(IP_MULTICAST_LOOP)   failed:   %d/n ",     
                        WSAGetLastError()); 
                        AfxMessageBox(szPromoteMsg); 

                        return   ; 
                } 
        } 
        bAllowedSending=TRUE; 
/* 
        BROADCASTPARAM   *pBroadcastParam=new   BROADCASTPARAM   ; 
        pBroadcastParam-> remote=remote; 
pBroadcastParam-> nRate=m_iRate; 
pBroadcastParam-> hBroadcastSocket=hSendSocket; 
pBroadcastParam-> bAllowedSending=bAllowedSending; 

AfxBeginThread(BroadcastThreadProc, 
                                                  (LPVOID)pBroadcastParam, 
  THREAD_PRIORITY_NORMAL, 
  0, 
  0, 
  NULL); 
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值