Boost logo

Boost Users :

Subject: [Boost-users] passing socket descriptor to a function
From: pedro chaparro (pdro07_at_[hidden])
Date: 2010-01-27 07:23:30


Hi, i have the code below, i want to separate the open socket code from the
writting fucntions, i want to call a escribir() function from the main but
i¡m not clear the value i have to pass the function, inthe way i have below
it has not work.
thanks
#include <ctime>
#include <iostream>
#include <string>
#include <boost/asio.hpp>

using boost::asio::ip::tcp;

void escribir( tcp::socket socket){

  std::string message = "mensaje";

      boost::system::error_code ignored_error;
      boost::asio::write(socket, boost::asio::buffer(message),
          boost::asio::transfer_all(), ignored_error);

}

int main()
{ int contador=0;

  try
  {
    boost::asio::io_service io_service;

    tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 5544));
 for (;;)
    {
      tcp::socket socket(io_service);
      acceptor.accept(socket);
      escribir(socket);
    }

  }
  catch (std::exception& e)
  {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}

-- 
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