本文整理汇总了C++中SocketPtr::close方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketPtr::close方法的具体用法?C++ SocketPtr::close怎么用?C++ SocketPtr::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketPtr
的用法示例。
在下文中一共展示了SocketPtr::close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Run
///////////////////////////////////////////////////////////////////////
// Starts Request Server in Thread.
///////////////////////////////////////////////////////////////////////
void Run()
{
active_ = true;
std::string reply_msg;
std::string data;
gnuradar::ControlMessage request_msg;
gnuradar::ResponseMessage response_msg;
zmq::message_t request;
while( active_ )
{
// Wait for next request from client.
socket_->recv (&request);
// Parse message from wire.
request_msg.ParseFromString( zmq_helper::FormatString(request) );
// Execute client request
response_msg = this->ExecuteRequest( request_msg );
// Send reply
this->SendResponse( response_msg );
}
std::cout << "CLOSING REQUEST SERVER SOCKET" << std::endl;
socket_->close();
}
示例2: 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();
}
示例3:
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);
}
}
}
示例4: Run
void Run()
{
std::cout << "StatusServer: START " << std::endl;
active_ = true;
gnuradar::StatusMessage status_msg;
while( active_ )
{
status_msg.set_name("status");
status_msg.set_head(pcModel_->Head() );
status_msg.set_tail(pcModel_->Tail() );
status_msg.set_depth( pcModel_->Depth());
status_msg.set_over_flow(pcModel_->OverFlow() );
status_msg.set_bytes_per_buffer( pcModel_->BytesPerBuffer() );
std::string data;
status_msg.SerializeToString(&data);
zmq::message_t zmq_msg(data.size());
memcpy ((void *) zmq_msg.data(), data.c_str(), data.size());
socket_->send (zmq_msg);
Sleep(thread::MSEC, gnuradar::constants::STATUS_REFRESH_RATE_MSEC);
}
std::cout << "StatusServer: STOP " << std::endl;
socket_->close();
}
示例5: downloadAllThumbFiles
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();
}
}
}
示例6: downloadSoap
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;
}
示例7: downloadAllBinFiles
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();
}
示例8: connect
SocketPtr Downloader::connect(const std::string& url)
{
tcp::resolver resolver(*(mService));
tcp::resolver::query query(url, "http");
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::resolver::iterator end;
SocketPtr socket = SocketPtr(new tcp::socket(*(mService)));
boost::system::error_code error = boost::asio::error::host_not_found;
while (error && endpoint_iterator != end)
{
socket->close();
socket->connect(*endpoint_iterator++, error);
}
if (error)
throw boost::system::system_error(error);
return socket;
}
示例9: downloadCollection
bool TileDownloader::downloadCollection(const std::string& collectionFilePath, const std::string& collectionUrl)
{
try
{
std::string host = DownloadHelper::extractHost(collectionUrl);
SocketPtr sock = DownloadHelper::connect(mService, host);
std::string header = DownloadHelper::createGETHeader(DownloadHelper::removeHost(collectionUrl, 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));
sock->close();
//skip header from response
std::istream response_stream(&response);
std::string line;
while (std::getline(response_stream, line) && line != "\r");
//put collection into collectionText
std::stringstream collectionText;
while (std::getline(response_stream, line))
collectionText << line << std::endl;
//save collection
if (!DownloadHelper::saveAsciiFile(collectionFilePath, collectionText.str()))
return false;
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
return false;
}
return true;
}
示例10: downloadJson
bool Downloader::downloadJson(const std::string& guid, const std::string& jsonUrl)
{
try
{
std::string host = extractHost(jsonUrl);
SocketPtr sock = connect(host);
std::string header = createGETHeader(removeHost(jsonUrl, 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));
sock->close();
//skip header from response
std::istream response_stream(&response);
std::string line;
while (std::getline(response_stream, line) && line != "\r");
//put json into jsonText
std::stringstream jsonText;
while (std::getline(response_stream, line))
jsonText << line << std::endl;
//save json
if (!saveAsciiFile(Parser::createFilePath(guid, Parser::jsonFilename), jsonText.str()))
return false;
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
return false;
}
return true;
}