本文整理汇总了C++中UdpServer::InitializeMulticastSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpServer::InitializeMulticastSocket方法的具体用法?C++ UdpServer::InitializeMulticastSocket怎么用?C++ UdpServer::InitializeMulticastSocket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpServer
的用法示例。
在下文中一共展示了UdpServer::InitializeMulticastSocket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ServerUDP
void ServerUDP()
{
UdpServer server;
Packet data;
IP4Address source;
//server.SetNetworkInterface(0); // If you wanted to specifiy a network interface to receive on.
data.SetByteOrder(CX_PACKET_BIG_ENDIAN);
if(!server.InitializeMulticastSocket(PORT, MULTICAST_GROUP))
{
cout << "Unable to initialize on port " << PORT << endl;
return;
}
cout << "Initialized UDP Server Socket on port " << PORT << endl;
char key = 0;
while(key != 27)
{
// Do non-blocking receive for data (wait 100 ms).
if(server.Recv(data, 500, 100, &source) > 0) // Receive up to 500 bytes to packet.
{
cout << source.mString << " Sent (" << data.Size() << " bytes): ";
char val;
while(data.Read(val))
cout << val;
cout << endl;
}
key = GetChar(); // Get key.
}
}