多播在 Windows Vista 上不工作

发布于 2024-10-07 11:10:02 字数 1599 浏览 1 评论 0原文

当我尝试在 win XP 中对 IP 范围进行多播时,它工作正常,但是当我在 Win VIsta 上运行相同的应用程序时,我无法进行多播。我需要为 Win Vitsa 配置或添加发布商信息吗?

编辑:

struct sockaddr_in staddr;
    memset(&staddr, 0, sizeof(struct sockaddr_in));
    staddr.sin_family = AF_INET;
    staddr.sin_port = htons(SSDP_PORT); // Use the first free port
    staddr.sin_addr.s_addr=inet_addr(SSDP_MULTICAST_ADDRESS);

    int socklen = sizeof(struct sockaddr_in);

编辑 2

Socket Creation
int ibindstatus =0 ;
    try
    {
    //Initailize the WinSock
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2,2), &wsaData);

   struct in_addr iaddr;
   struct sockaddr_in staddr;
   // set content of struct saddr and imreq to zero
   memset(&staddr, 0, sizeof(struct sockaddr_in));
   memset(&iaddr, 0, sizeof(struct in_addr));

   // open a UDP socket

   m_iSocket = socket(AF_INET, SOCK_DGRAM, 0);
   if ( m_iSocket < 0 )     
    {       
      return SOCKET_NOT_AVAILABLE;
    } 

   staddr.sin_family = AF_INET;
   staddr.sin_port = htons(SSDP_PORT); // Use the first free port
   staddr.sin_addr.s_addr = htonl(INADDR_ANY); // bind socket to any interface 

   ibindstatus = bind(m_iSocket, (struct sockaddr *)&staddr, sizeof(struct sockaddr_in));
   if ( ibindstatus < 0 )
   {
      return SOCKET_BIND_ERROR;
   }


    //send the buffer
    int iSendStatus = sendto(m_iSocket, cSendData, lSendDataLen, 0,
                     (struct sockaddr *)&staddr, socklen);  
    if(iSendStatus< 0)
    {
       return SEND_ERROR;      
    }

While I try to Multicast something to range of IP in win XP , it works fine but while I run the same application on Win VIsta I am unable to multicast. Do I need to configure or add a publisher info for Win Vitsa?

Edit:

struct sockaddr_in staddr;
    memset(&staddr, 0, sizeof(struct sockaddr_in));
    staddr.sin_family = AF_INET;
    staddr.sin_port = htons(SSDP_PORT); // Use the first free port
    staddr.sin_addr.s_addr=inet_addr(SSDP_MULTICAST_ADDRESS);

    int socklen = sizeof(struct sockaddr_in);

Edit 2

Socket Creation
int ibindstatus =0 ;
    try
    {
    //Initailize the WinSock
    WSADATA wsaData;
    WSAStartup(MAKEWORD(2,2), &wsaData);

   struct in_addr iaddr;
   struct sockaddr_in staddr;
   // set content of struct saddr and imreq to zero
   memset(&staddr, 0, sizeof(struct sockaddr_in));
   memset(&iaddr, 0, sizeof(struct in_addr));

   // open a UDP socket

   m_iSocket = socket(AF_INET, SOCK_DGRAM, 0);
   if ( m_iSocket < 0 )     
    {       
      return SOCKET_NOT_AVAILABLE;
    } 

   staddr.sin_family = AF_INET;
   staddr.sin_port = htons(SSDP_PORT); // Use the first free port
   staddr.sin_addr.s_addr = htonl(INADDR_ANY); // bind socket to any interface 

   ibindstatus = bind(m_iSocket, (struct sockaddr *)&staddr, sizeof(struct sockaddr_in));
   if ( ibindstatus < 0 )
   {
      return SOCKET_BIND_ERROR;
   }


    //send the buffer
    int iSendStatus = sendto(m_iSocket, cSendData, lSendDataLen, 0,
                     (struct sockaddr *)&staddr, socklen);  
    if(iSendStatus< 0)
    {
       return SEND_ERROR;      
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌无敌 2024-10-14 11:10:02

经过大量实验后,我无法弄清楚为什么多重投射不起作用,突然发现这是因为我的 Vista 上的 网络发现 被关闭了。

因此,如果我在这里做了什么,请转到控制面板->设置文件共享(在网络和互联网下)->共享和发现,然后打开或关闭网络发现

那么,对我的应用程序有用的内容和源代码就是我在问题中发布的内容。完全希望这会节省您的一些时间和挫败感。

Well after lotz of experiments I was not able to figure out why Multi casting was not working, and found out suddenly this is because Network Discovery was off on my Vista.

So If here what I did , Go to Control Panel->SetUp File Sharing(Under Network and Internet) ->Sharing and Discovery and then switch on or off the network discovery

Well thatz what work for my application and the source code is what I have posted in my question. Hope fully this will save some of your time and frustation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文