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


C++ SocketPtr类代码示例

本文整理汇总了C++中SocketPtr的典型用法代码示例。如果您正苦于以下问题:C++ SocketPtr类的具体用法?C++ SocketPtr怎么用?C++ SocketPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: OnRecvBody

void AcceptSession::OnRecvBody(SocketPtr socket_ptr, const boost::system::error_code& error)
{
  if (!error)
  {
    m_network_mgr->OnRecv(socket_ptr);

    if (socket_ptr->GetSocket().is_open())
    {
      socket_ptr->ChangeBufferSize(MESSAGE_HEADER_LENGTH);
      boost::asio::async_read(socket_ptr->GetSocket(),
                              boost::asio::buffer(socket_ptr->GetBuffer(), MESSAGE_HEADER_LENGTH),
                              boost::bind(&AcceptSession::OnRecvHead, this, socket_ptr, boost::asio::placeholders::error));
    }
  }
  else
  {
    if (error == boost::asio::error::eof)
    {
      std::stringstream ss;
      ss << "AcceptSession::OnRecvBody Error : " << error.message();
      DebugMessage::GetInstance()->ShowMessage(DebugMessageType::BASE_NETWORK, ss.str());
    }

    if (NULL != m_network_mgr && socket_ptr->GetSocket().is_open())
      m_network_mgr->OnDisconnect(socket_ptr);
  }
}
开发者ID:face2wind,项目名称:CodingProjects,代码行数:27,代码来源:accept_session.cpp

示例2: connect

bool Downloader::downloadSoap(const std::string& guid)
{
	try
	{
		SocketPtr sock = connect("www.photosynth.net");

		//prepare header + content
		std::stringstream content;
		content << "<?xml version=\"1.0\" encoding=\"utf-8\"?>"<<std::endl;
		content << "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"<<std::endl;
		content << "	<soap12:Body>"<<std::endl;
		content << "		<GetCollectionData xmlns=\"http://labs.live.com/\">"<<std::endl;
		content << "		<collectionId>"<<guid<<"</collectionId>"<<std::endl;
		content << "		<incrementEmbedCount>false</incrementEmbedCount>"<<std::endl;
		content << "		</GetCollectionData>"<<std::endl;
		content << "	</soap12:Body>"<<std::endl;
		content << "</soap12:Envelope>"<<std::endl;

		std::stringstream header;
		header << "POST /photosynthws/PhotosynthService.asmx HTTP/1.1"<<std::endl;
		header << "Host: photosynth.net"<<std::endl;
		header << "Content-Type: application/soap+xml; charset=utf-8"<<std::endl;
		header << "Content-Length: "<<content.str().size()<<std::endl;
		header << ""<<std::endl;

		//send header + content
		boost::system::error_code error;
		boost::asio::write(*sock, boost::asio::buffer(header.str().c_str()), boost::asio::transfer_all(), error);
		boost::asio::write(*sock, boost::asio::buffer(content.str().c_str()), boost::asio::transfer_all(), error);

		sock->shutdown(tcp::socket::shutdown_send);

		//read the response
		boost::asio::streambuf response;
		while (boost::asio::read(*sock, response, boost::asio::transfer_at_least(1), error));

		sock->close();

		std::istream response_stream(&response);
		std::string line;

		//skip header from response
		while (std::getline(response_stream, line) && line != "\r");		

		//put soap response into xml
		std::stringstream xml;
		while (std::getline(response_stream, line))
			xml << line << std::endl;

		//save soap response
		if (!saveAsciiFile(Parser::createFilePath(guid, Parser::soapFilename), xml.str()))
			return false;		
	}
	catch (std::exception& e)
	{		
		std::cerr << e.what() << std::endl;
		return false;
	}
	return true;
}
开发者ID:aufheben1,项目名称:visual-experiments,代码行数:60,代码来源:PhotoSynthDownloader.cpp

示例3: while

void TelnetAppender::SocketHandler::run()
{
	while(!done)
	{
		try 
		{
			SocketPtr newClient = serverSocket.accept();
			SocketOutputStreamPtr os = newClient->getOutputStream();
			if(connections.size() < MAX_CONNECTIONS)
			{
				connections.push_back(newClient);
				writers.push_back(os);

				StringBuffer oss;
				oss << _T("TelnetAppender v1.0 (") << connections.size()
					<< _T(" active connections)\r\n\r\n");
				print(os, oss.str());
				os->flush();
			} 
			else
			{
				print(os, _T("Too many connections.\r\n"));
				os->flush();
				newClient->close();
			}
		} 
		catch(Exception& e) 
		{
			LogLog::error(_T("Encountered error while in SocketHandler loop."), e);
		}
	}
}
开发者ID:Amakata,项目名称:wajima,代码行数:32,代码来源:telnetappender.cpp

示例4: sprintf

void Downloader::downloadAllThumbFiles(const std::string& guid, const JsonInfo& info)
{
	for (unsigned int i=0; i<info.thumbs.size(); ++i)
	{
		char buf[10];
		sprintf(buf, "%08d", i);

		std::stringstream filename;
		filename << "thumbs/" << buf << ".jpg";

		std::string filepath = Parser::createFilePath(guid, filename.str());
		if (!bf::exists(filepath))
		{
			std::string host = extractHost(info.thumbs[i].url);
			SocketPtr sock = connect(host);

			std::string header = createGETHeader(removeHost(info.thumbs[i].url, host), host);

			//send GET request
			boost::system::error_code error;
			boost::asio::write(*sock, boost::asio::buffer(header.c_str()), boost::asio::transfer_all(), error);

			//read the response (header + content)
			boost::asio::streambuf response;
			while (boost::asio::read(*sock, response, boost::asio::transfer_at_least(1), error));

			std::istream response_stream(&response);
			int length = getContentLength(response_stream);

			saveBinFile(filepath, response_stream, length);

			sock->close();
		}
	}
}
开发者ID:aufheben1,项目名称:visual-experiments,代码行数:35,代码来源:PhotoSynthDownloader.cpp

示例5: downloadPictureTile

void TileDownloader::downloadPictureTile(unsigned int pictureIndex, unsigned int tileIndex)
{
	TileInfo& tileInfo = mPictures[pictureIndex].tiles[tileIndex];
	std::string url      = tileInfo.url;
	std::string filepath = tileInfo.filePath;

	std::string host = DownloadHelper::extractHost(url);
	SocketPtr sock = DownloadHelper::connect(mService, host);

	std::string header = DownloadHelper::createGETHeader(DownloadHelper::removeHost(url, host), host);

	//send GET request
	boost::system::error_code error;
	boost::asio::write(*sock, boost::asio::buffer(header.c_str()), boost::asio::transfer_all(), error);

	//read the response (header + content)
	boost::asio::streambuf response;
	while (boost::asio::read(*sock, response, boost::asio::transfer_at_least(1), error));

	std::istream response_stream(&response);
	int length = DownloadHelper::getContentLength(response_stream);
	tileInfo.size = (unsigned int) length;

	DownloadHelper::saveBinFile(filepath, response_stream, length);			

	sock->close();
}
开发者ID:SimplyNishant,项目名称:PhotoSynthToolkit,代码行数:27,代码来源:PhotoSynthTileDownloader.cpp

示例6: get_network_thread_for_new_connection

void NetworkManager::AcceptNewConnection()
{
    NetworkThread& worker = get_network_thread_for_new_connection();
    SocketPtr connection = CreateSocket(worker);

    acceptor_->async_accept(connection->socket(),
        boost::bind(&NetworkManager::OnNewConnection, this, connection, boost::asio::placeholders::error));
}
开发者ID:beyourself,项目名称:RustEmu-Core,代码行数:8,代码来源:NetworkManager.cpp

示例7: send_data

void
send_data( const SocketPtr &in_socket, const std::string &in_msg ) {
    if( in_socket->get_is_connected() )
    {
        MemInfo info( in_msg.c_str(), in_msg.length() + 1 );
        in_socket->send_data( info );
    }
}
开发者ID:Tushar-Naik,项目名称:hpcl,代码行数:8,代码来源:client.cpp

示例8: OnAccept

void OnAccept(const AsyncResultPtr &asyncResult)
{
	try {
		SocketPtr listenSocket = asyncResult->asyncState;
		SocketPtr acceptSocket = listenSocket->EndAccept(asyncResult);
		acceptSocket->BeginReceive(BufferPtr(8192, NoRebindTag()), &OnReceive, acceptSocket);
		listenSocket->BeginAccept(&OnAccept, listenSocket);
	} catch (const std::exception &) {
	}
}
开发者ID:xeon2007,项目名称:magicsocket,代码行数:10,代码来源:Main.cpp

示例9: main

int main()
{
	try {
		SocketPtr listenSocket;
		listenSocket->Bind(7777);
		listenSocket->Listen();
		listenSocket->BeginAccept(&OnAccept, listenSocket);
		Sleep(INFINITE);
	} catch (const std::exception &) {
	}
}
开发者ID:xeon2007,项目名称:magicsocket,代码行数:11,代码来源:Main.cpp

示例10: extractHost

void Downloader::downloadAllBinFiles(const std::string& guid, Parser* parser)
{
	std::string host = extractHost(parser->getSoapInfo().collectionRoot);

	SocketPtr sock = connect(host);
	boost::asio::socket_base::keep_alive keepAlive(true);
	sock->set_option(keepAlive);

	std::stringstream headers;
	std::vector<std::string> filenames;

	int nbCoorSystem = parser->getNbCoordSystem();

	for (unsigned int i=0; i<parser->getNbCoordSystem(); ++i)
	{
		int nbPointCloud = parser->getNbPointCloud(i);
		for (unsigned int j=0; j<parser->getNbPointCloud(i); ++j)
		{
			std::stringstream filename;
			filename << "bin/points_"<< i << "_" << j << ".bin";
			if (!bf::exists(Parser::createFilePath(guid, filename.str())))
			{
				filenames.push_back(filename.str());
				std::stringstream url;
				url << parser->getSoapInfo().collectionRoot << filename.str().substr(4);
				headers << createGETHeader(removeHost(url.str(), host), host);
			}
		}
	}

	if (filenames.size() > 0)
	{
		//send GET request
		boost::system::error_code error;
		boost::asio::write(*sock, boost::asio::buffer(headers.str().c_str()), boost::asio::transfer_all(), error);

		//read the response (header + content)
		boost::asio::streambuf response;
		while (boost::asio::read(*sock, response, boost::asio::transfer_at_least(1), error));

		//read all response header and content
		std::istream response_stream(&response);
		for (unsigned int i=0; i<filenames.size(); ++i)
		{
			int length = getContentLength(response_stream);
			saveBinFile(Parser::createFilePath(guid, filenames[i]), response_stream, length);
		}
	}

	sock->close();
}
开发者ID:aufheben1,项目名称:visual-experiments,代码行数:51,代码来源:PhotoSynthDownloader.cpp

示例11: OnReceive

void OnReceive(const AsyncResultPtr &asyncResult)
{
	try {
		SocketPtr acceptSocket = asyncResult->asyncState;
		BufferPtr buffer = asyncResult->buffer;
		size_t size = acceptSocket->EndReceive(asyncResult);
		if (size != 0) {
			buffer->Resize(size);
			acceptSocket->BeginSend(buffer);
			acceptSocket->BeginReceive(BufferPtr(8192, NoRebindTag()), &OnReceive, acceptSocket);
		} else {
			acceptSocket->BeginDisconnect();
		}
	} catch (const std::exception &) {
	}
}
开发者ID:xeon2007,项目名称:magicsocket,代码行数:16,代码来源:Main.cpp

示例12: string

 //-----------------------------------------------------------------------
 String string(const SocketPtr & x)
 {
   if (!x) return String();
   auto socket = x->getSocket();
   if (INVALID_SOCKET == socket) return "INVALID_SOCKET";
   return string(((PTRNUMBER)(socket)));
 }
开发者ID:openpeer,项目名称:zsLib,代码行数:8,代码来源:zsLib_Stringize.cpp

示例13: OnSocketOpen

bool NetworkManager::OnSocketOpen(const SocketPtr& socket)
{
    NetworkThread& thread = socket->owner();
    thread.AddSocket(socket);

    return true;
}
开发者ID:beyourself,项目名称:RustEmu-Core,代码行数:7,代码来源:NetworkManager.cpp

示例14: StatusServer

         StatusServer( zmq::context_t& ctx, const std::string& ipAddr, PcModelPtr pcModel ) : pcModel_(pcModel) 
         {
            socket_ = SocketPtr( new zmq::socket_t(ctx, ZMQ_PUB));
				//socket_->setsockopt( ZMQ_HWM, &gnuradar::constants::HWM, sizeof(gnuradar::constants::HWM));
            socket_->bind (ipAddr.c_str());
				std::cout << "STATUS ADDRESS : " << ipAddr << std::endl;
         }
开发者ID:hamarpaul,项目名称:GnuRadar,代码行数:7,代码来源:StatusServer.hpp

示例15: addFD

void Poll::addFD(SocketPtr sock, PollHandler handler)
{
	static struct epoll_event ev;

	{
		std::unique_lock<std::mutex> lock(mutex_);
		handlers_[sock->native()] = std::make_tuple(sock, handler);
	}

	ev.events = /*EPOLLET |*/ EPOLLIN | EPOLLOUT;
	ev.data.fd = sock->native();

	int ret = epoll_ctl(fd_, EPOLL_CTL_ADD, sock->native(), &ev);
	if (ret != 0)
	{
		THROW_SYSTEM_ERROR();
	}
}
开发者ID:ClickSmile,项目名称:httpd,代码行数:18,代码来源:Poll.cpp


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