本文整理汇总了C++中TcpSocket::GetPeer方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::GetPeer方法的具体用法?C++ TcpSocket::GetPeer怎么用?C++ TcpSocket::GetPeer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::GetPeer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AcceptClients
void Server::AcceptClients()
{
TcpSocket c;
Address from;
if(c.Accept(server, from, false))
{
std::wstring name = c.GetPeer().ToString(false);
// Check password.
Packet p;
if(c.Receive(&p, sizeof(p), 1000) == sizeof(p) && (p.Control == C_CONNECT || p.Control == C_RESUME))
{
if(password == 0 || password == ntohl(p.Password))
{
// Check if a client is being booted by the new client.
if(client.IsValid())
{
std::wstring name = client.GetPeer().ToString(false);
client.Close();
if(p.Control != C_RESUME)
Log(OL_INFO, L"Replacing client %s\r\n", name.c_str());
}
if(p.Control == C_CONNECT)
Log(OL_NOTIFY | OL_INFO, L"Client connected from %s\r\n", name.c_str());
else
Log(OL_INFO, L"Client resumed\r\n");
p.Control = C_CONNECT;
c.Send(&p, sizeof(p));
client.Take(c);
}
else
{
p.Control = C_DISCONNECT;
p.Reason = 1;
Log(OL_INFO, L"Rejected client %s: Bad password\r\n", name.c_str());
}
}
else
{
p.Control = C_DISCONNECT;
p.Reason = 0;
Log(OL_INFO, L"Client failed to connect from %s\r\n", name.c_str());
}
if(p.Control == C_DISCONNECT)
{
c.Send(&p, sizeof(p));
c.Close();
}
}
}