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


C++ socket::is_open方法代码示例

本文整理汇总了C++中ip::tcp::socket::is_open方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::is_open方法的具体用法?C++ socket::is_open怎么用?C++ socket::is_open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ip::tcp::socket的用法示例。


在下文中一共展示了socket::is_open方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: get_public_key_resp

ed_key c_netuser::get_public_key_resp(ip::tcp::socket &socket_) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
	boost::system::error_code ec;

	char header[2];
	DBG_MTX(dbg_mtx, "read header");
    size_t pkresp = socket_.read_some(buffer(header, 2), ec);
    DBG_MTX(dbg_mtx, "pk: " << pkresp << ":[" <<header[0] << header[1] << "]");

	DBG_MTX(dbg_mtx, "read public key size");
    size_t pub_key_size = 4;
    uint32_t key_size = 0;
    size_t recieved_bytes = socket_.read_some(buffer(&key_size, pub_key_size), ec);
    DBG_MTX(dbg_mtx, "size:" << recieved_bytes << ":[" <<key_size << "]");

    assert(recieved_bytes == pub_key_size);

    const std::unique_ptr<unsigned char[]> pub_key_data(new unsigned char[key_size]);

	DBG_MTX(dbg_mtx, "read public key data");
    recieved_bytes = socket_.read_some(buffer(pub_key_data.get(), key_size), ec);
    DBG_MTX(dbg_mtx, "data:" << recieved_bytes << ":[" << ed_key(pub_key_data.get(),recieved_bytes) << "]");
    assert(recieved_bytes == key_size);

    ed_key pub_key(pub_key_data.get(), key_size);
	DBG_MTX(dbg_mtx, "END");
	return pub_key;
}
开发者ID:MichalTigu,项目名称:antinet,代码行数:29,代码来源:c_netuser.cpp

示例2: send_public_key_req

void c_netuser::send_public_key_req(ip::tcp::socket &socket_) {
	DBG_MTX(dbg_mtx, "send public key request");
	assert(socket_.is_open());
    boost::system::error_code ec;
    char pubkey_send_req[2] = {'p','k'};
    size_t sendbytes = socket_.write_some(boost::asio::buffer(pubkey_send_req, request_type_size),ec);
    DBG_MTX(dbg_mtx, "pk: " << sendbytes << ":[" << pubkey_send_req[0] <<  pubkey_send_req[1] << "]");

}
开发者ID:MichalTigu,项目名称:antinet,代码行数:9,代码来源:c_netuser.cpp

示例3: send_coin

void c_netuser::send_coin(ip::tcp::socket &socket_, const std::string &coin_data) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
    boost::system::error_code ec;
	char header[2] = {'$', 't'};
	socket_.write_some(buffer(header, 2), ec);

	uint32_t coin_data_size = coin_data.size();
	socket_.write_some(buffer(&coin_data_size, 4), ec);

	socket_.write_some(buffer(coin_data), ec);
}
开发者ID:MichalTigu,项目名称:antinet,代码行数:12,代码来源:c_netuser.cpp

示例4: close

 virtual void close() {
   if (!closed) closed = 1;
   
   if (clientSocket->is_open()) {
     clientSocket->cancel();
     clientSocket->close();
   }
   
   if (serverSocket.is_open()) {
     serverSocket.cancel();
     serverSocket.close();
   }
 }
开发者ID:Andlab,项目名称:sslsniff,代码行数:13,代码来源:RawBridge.hpp

示例5: send_public_key_resp

void c_netuser::send_public_key_resp(ip::tcp::socket &socket_) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
	boost::system::error_code ec;
	char header[2] = {'p', 'k'};
	DBG_MTX(dbg_mtx, "send header");
	socket_.write_some(buffer(header, 2), ec);
	//uint32_t packet_size = ed25519_sizes::pub_key_size;
    ed_key packet = get_public_key();
	uint32_t packet_size = packet.size();
	// TODO send binary data
	DBG_MTX(dbg_mtx,"send public key size" << "[" << packet_size << "]");
    socket_.write_some(boost::asio::buffer(&packet_size, 4), ec);

    DBG_MTX(dbg_mtx,"send public key data" << "[" << packet << "]");
    socket_.write_some(boost::asio::buffer(packet.c_str(), packet_size), ec);
    DBG_MTX(dbg_mtx,"end of sending public key");
}
开发者ID:MichalTigu,项目名称:antinet,代码行数:18,代码来源:c_netuser.cpp

示例6: server_read

void c_netuser::server_read(ip::tcp::socket socket_) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
    boost::system::error_code ec;
    DBG_MTX(dbg_mtx,"server read");
	while (!ec && !m_stop_flag) {
		char header[2] = {0, 0};
		socket_.read_some(buffer(header, 2), ec);
		if (header[0] == 'p' && header[1] == 'k') {
			send_public_key_resp(socket_);
		}
		else if (header[0] == '$' && header[1] == 't') {
			std::string coin_data = recv_coin(socket_);
			recieve_from_packet(coin_data);
		}
	}
	socket_.close();
}
开发者ID:MichalTigu,项目名称:antinet,代码行数:18,代码来源:c_netuser.cpp

示例7: recv_coin

string c_netuser::recv_coin(ip::tcp::socket &socket_) {
	DBG_MTX(dbg_mtx, "START");
	assert(socket_.is_open());
	boost::system::error_code ec;

    size_t recieved_bytes = 0;

	uint32_t coin_size = 0;
	recieved_bytes = socket_.read_some(buffer(&coin_size, 4), ec);
	DBG_MTX(dbg_mtx, "get " << recieved_bytes << " bytes");
	assert(recieved_bytes == 4);

	const std::unique_ptr<char[]> coin_data(new char[coin_size]);

	recieved_bytes = socket_.read_some(buffer(coin_data.get(), coin_size), ec);
	assert(recieved_bytes == coin_size);
	return std::string(coin_data.get(), coin_size);
}
开发者ID:MichalTigu,项目名称:antinet,代码行数:18,代码来源:c_netuser.cpp


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