多播在 Windows Vista 上不工作
当我尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过大量实验后,我无法弄清楚为什么多重投射不起作用,突然发现这是因为我的 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.