本文整理汇总了C++中TcpServer::Recv方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpServer::Recv方法的具体用法?C++ TcpServer::Recv怎么用?C++ TcpServer::Recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpServer
的用法示例。
在下文中一共展示了TcpServer::Recv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ServerTCP
void ServerTCP()
{
TcpListenSocket listen;
TcpServer server;
Packet data;
string source;
data.SetByteOrder(CX_PACKET_BIG_ENDIAN);
// Tests non-blocking TCP connections. If listen socket is non-blocking
// then all TCP connections generated will be non-blocking.
if(!listen.InitializeSocket(PORT, 5U, 0U, 0U, 1, 1))
{
cout << "Unable to initialize listen socket on port " << PORT << endl;
return;
}
cout << "Initialized TCP Listen Socket\n";
cout << "Waiting for a connection.... ";
while( true )
{
if(listen.AwaitConnection(server))
{
cout << "Connection Made!\n";
while(true)
{
if(server.Recv(data, 50, 0) > 0) // Receive up to 50 bytes to packet.
{
cout << "Received: ";
char val;
while(data.Read(val))
{
cout << val;
server.Send(data);
}
cout << endl;
}
CxUtils::SleepMs(1);
}
cout << "Connection Closed.\n";
}
SleepMs(1);
}
}