本文整理汇总了C++中TcpSocket::recv方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::recv方法的具体用法?C++ TcpSocket::recv怎么用?C++ TcpSocket::recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::recv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
static TcpSocket *clientConnect(SOCKET serverSocket, sockaddr_in *host)
{
sockaddr_in hostTemp;
int hostSize = sizeof(sockaddr_in);
SOCKET clientSocket = accept(serverSocket, (sockaddr*)&hostTemp, &hostSize);
if (INVALID_SOCKET == clientSocket)
return NULL;
const char *expectedGreeting = CLIENT_GREET;
std::string line;
line.resize(0);
for (;;) {
char ch;
if (recv(clientSocket, &ch, 1, 0) != 1) {
closesocket(clientSocket);
return NULL;
}
if (ch == '\n')
break;
if (ch != '\r')
line.push_back(ch);
if (ch == '!')
break;
}
TcpSocket *ret = NULL;
if (!line.compare(0, 4, "GET ")) {
ret = WebSocket::upgradeFromHttp(clientSocket);
line.resize(strlen(expectedGreeting));
if (!ret || !ret->recv(&line[0], line.length())) {
closesocket(clientSocket);
return NULL;
}
} else
ret = new TcpSocket(clientSocket);
if (line.compare(0, strlen(expectedGreeting), expectedGreeting) ||
!ret->send(SERVER_GREET, strlen(SERVER_GREET), true)) {
ret->disconnect();
return NULL;
}
if (NULL != host)
*host = hostTemp;
return ret;
}