组播
来源:互联网 发布:java编程思想第5版txt 编辑:程序博客网 时间:2024/04/29 08:37
组播播出程序中主要的代码:
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);
*/
- 多播,组播
- 多播、组播
- 多播,组播
- “单播”“组播”和“多播”
- 单播、广播、组播(多播)
- 单播、广播、组播(多播)
- 单播 多播 组播
- 单播,组播,多播
- 单播,组播,广播,任播
- 组播
- 组播
- 组播
- 组播
- 组播
- 组播
- 组播
- 组播
- 组播
- 第三部分 线程安全(3)——线程同步
- C# 下获取搜索的文件
- 枚举PspCidTable利用API
- container_of()宏
- WMSYS.WM_CONCAT 函數的用法
- 组播
- 使用ContentProvider(内容提供者)共享数据
- 少走弯路:学习编译原理的相关建议
- Flex之组建样式CSS(3全部可用4可用一部分)1
- 《华清远见学习手记》 之3G智能机器人——视频监控客户端软件的设计与实现
- C++ Builder 中的自画功能
- Flex之组建样式CSS(3全部可用4可用一部分) 2
- How to Prepare the Windows Azure Compute Emulator
- Flex之组建样式CSS(3全部可用4可用一部分)3