|
Boost Users : |
Subject: [Boost-users] how to share information about a open socket?
From: pedro chaparro (pdro07_at_[hidden])
Date: 2010-03-08 04:32:50
Hi, based on the example
http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/tutorial/tutdaytime2.html,
i wanna to separate the part of the code that open de connection , and
the
part of the code that write a string over the socket, the problem is , that
i have no clear how to share the information of the socket between the both
fuctions. In this code below i suppose that listen fucion must to return the
socket information, but what data type must the function listen() return???
thanks so much in advance
void Agent::listen()
{
try
{
printf("SERVER A STARTED UDPsk \n");
boost::asio::io_service io_service;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 7777));
//for (;;)
{
tcp::socket socket(io_service);
acceptor.accept(socket);
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}
void Agent::write()
{
try
{
std::string message = "mymsg";
boost::system::error_code ignored_error;
boost::asio::write(socket, boost::asio::buffer(message),
boost::asio::transfer_all(), ignored_error);
sleep(1);
socket.close();
return;
}
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}
-- Ing Pedro Alonso Chaparro Valero Ciudad Politecnica de la Innovación iTEAM - Mobile Communications Group Polytechnic University of Valencia C\ Camino de Vera S/N, Edificio 8G 46022 Valencia, Spain
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net