当前位置: 首页>>代码示例>>C++>>正文


C++ TcpSocket::disconnect方法代码示例

本文整理汇总了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();
}
开发者ID:Ceylo,项目名称:CryptoA5,代码行数:30,代码来源:client.cpp

示例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;
}
开发者ID:Web5design,项目名称:rocket,代码行数:48,代码来源:editor.cpp

示例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;
	}
}
开发者ID:noriter,项目名称:nit,代码行数:16,代码来源:Socket.cpp


注:本文中的TcpSocket::disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。