本文整理汇总了C++中TcpSocket::disconnect方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::disconnect方法的具体用法?C++ TcpSocket::disconnect怎么用?C++ TcpSocket::disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::disconnect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: client
void client()
{
TcpSocket socket;
Socket::Status status = socket.connect(IpAddress::getLocalAddress(), DH_PORT);
if (status != Socket::Status::Done)
{
perror("connection to server failed");
return;
}
mpz_t secret;
CurveRef curve = client_receive_curve(socket);
PointRef p = client_create_key(socket, curve, secret);
client_send_key(socket, p);
PointRef remoteKey = client_receive_key(socket);
PointRef sharedSecret = PointCreateMultiple(remoteKey, secret, curve);
char *desc = PointCreateDescription(sharedSecret);
cout << "Secret: " << desc << endl;
free(desc);
mpz_clear(secret);
CurveDestroy(curve);
PointDestroy(p);
PointDestroy(remoteKey);
PointDestroy(sharedSecret);
socket.disconnect();
}
示例2: 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;
}
示例3: onDisconnect
void TcpSocketServer::onDisconnect()
{
for (Clients::iterator itr = _clients.begin(), end = _clients.end(); itr != end; ++itr)
{
TcpSocket* client = *itr;
client->disconnect();
if (_listener) _listener->onDisconnected(this, client);
}
_clients.clear();
if (_listening)
{
if (_listener) _listener->onShutdown(this);
_listening = false;
}
}