本文整理汇总了C++中Host::Receive方法的典型用法代码示例。如果您正苦于以下问题:C++ Host::Receive方法的具体用法?C++ Host::Receive怎么用?C++ Host::Receive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Host
的用法示例。
在下文中一共展示了Host::Receive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ServerThread
void* ServerThread(void*)
{
Host server;
std::string file = "out.log";
if (server.Listen(0xff))
{
puts("Server | listening...");
Host *connectedHost = server.Accept();
printf("Server | connected to %s on %i\n", connectedHost->GetIPAddress().c_str(), connectedHost->GetPort());
printf("Server | read: %s\n", connectedHost->Receive().c_str());
printf("Server | sent: %i bytes\n", connectedHost->Send("Data from server"));
printf("Server | read: %s\n", connectedHost->Receive().c_str());
printf("Server | sent: %i bytes\n", connectedHost->Send("Last message from server"));
printf("Server | file: %s | name: ", connectedHost->ReceiveFile(file) ? "good" : "bad");
puts(file.c_str());
if (connectedHost->Disconnect()) puts("Server | connection closed");
else puts("Server | cannot close connection");
delete connectedHost;
if (server.Disconnect()) puts("Server | socket closed");
else puts("Server | cannot close socket");
}
else puts("Server | cannot listen");
return NULL;
}
示例2: ClientThread
void* ClientThread(void*)
{
Host client;
if (client.Connect("localhost", 0xff))
{
printf("Client | connected to %s on %i\n", client.GetIPAddress().c_str(), client.GetPort());
printf("Client | sent: %i bytes\n", client.Send("Data from client"));
printf("Client | read: %s\n", client.Receive().c_str());
printf("Client | sent: %i bytes\n", client.Send("Last message from client"));
printf("Client | read: %s\n", client.Receive().c_str());
printf("Client | file: %s\n", client.SendFile("in.log") ? "good" : "bad");
if (client.Disconnect()) puts("Client | connection closed");
else puts("Client | cannot close connection");
}
else puts("Client | cannot connect");
return NULL;
}