本文整理汇总了C++中UdpServer::Recv方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpServer::Recv方法的具体用法?C++ UdpServer::Recv怎么用?C++ UdpServer::Recv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpServer
的用法示例。
在下文中一共展示了UdpServer::Recv方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UdpServerWorker
UINT __stdcall UdpServerWorker(PVOID context)
{
InitializeCriticalSection(&g_data_lock);
UdpServer server;
if (server.Init("127.0.0.1", (int)context)) {
std::vector<UCHAR> buffer;
buffer.resize(64 * 1024);
for (;;) {
sockaddr_in addr;
int recv_length = server.Recv((char *)buffer.data(), buffer.size(), &addr);
if (recv_length == -1) {
break;
}
EnterCriticalSection(&g_data_lock);
g_data_queue.push_back(std::vector<UCHAR>(buffer.begin(), buffer.begin() + recv_length));
LeaveCriticalSection(&g_data_lock);
SetEvent(g_data_event);
server.Send("OK", 3, &addr);
}
}
DeleteCriticalSection(&g_data_lock);
return 0;
}
示例2: 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.
}
}
示例3: UdpServerForIpWorker
UINT __stdcall UdpServerForIpWorker(PVOID context)
{
UdpServer server;
if (server.Init("127.0.0.1", (int)context)) {
std::vector<UCHAR> buffer;
buffer.resize(0x1000);
for (;;) {
sockaddr_in addr;
int recv_length = server.Recv((char *)buffer.data(), buffer.size(), &addr);
if (recv_length == -1) {
break;
}
server.Send("OK", 3, &addr);
}
}
return 0;
}