[Boost-users] invalid argument?

780 views
Skip to first unread message

pedro chaparro

unread,
Oct 16, 2009, 11:35:26 AM10/16/09
to boost...@lists.boost.org
hi, i working on the creation of a co-simulation framework , for that i'm using asio libraries and serialization to send exchange information between simulators, i'm getting a error that say me " invalid argument" but just that, i dont know about  what argument is refered =(. some know which could be the cause(s)?
thanks

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

Steven Watanabe

unread,
Oct 16, 2009, 3:50:18 PM10/16/09
to boost...@lists.boost.org
AMDG

pedro chaparro wrote:
> hi, i working on the creation of a co-simulation framework , for that i'm
> using asio libraries and serialization to send exchange information between
> simulators, i'm getting a error that say me " invalid argument" but just
> that, i dont know about what argument is refered =(. some know which could
> be the cause(s)?thanks
>

I'm guessing that this is a runtime error, not a compile time error?
How do you get the error message? Is it an exception or something else?

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Igor R

unread,
Oct 17, 2009, 11:41:05 AM10/17/09
to boost...@lists.boost.org
> hi, i working on the creation of a co-simulation framework , for that i'm using asio libraries and serialization to send exchange information between simulators, i'm getting a error that say me " invalid argument" but just that, i dont know about  what argument is refered =(. some know which could be the cause(s)?


Maybe you try to work with "unopened" socket - i.e. a socket object that doesn't have a valid handle.

pedro chaparro

unread,
Oct 20, 2009, 5:25:20 AM10/20/09
to boost...@lists.boost.org
yes, it is from a exception, i'm re-using the code on http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/example/serialization/client.cpp to implement a co-simulation framework using a famous simulator called network simulator 2, anyway , the runtime error comes when i try to do the connection with the server, the server is open in listening mode but i can not achieved establish the connection.

2009/10/16 Steven Watanabe <watan...@gmail.com>

Igor R

unread,
Oct 20, 2009, 5:29:51 AM10/20/09
to boost...@lists.boost.org
yes, it is from a exception, i'm re-using the code on http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/example/serialization/client.cpp to implement a co-simulation framework using a famous simulator called network simulator 2, anyway , the runtime error comes when i try to do the connection with the server, the server is open in listening mode but i can not achieved establish the connection.
 
 
Can you post the exact code that you use to "establish the connection"?

pedro chaparro

unread,
Oct 20, 2009, 5:43:19 AM10/20/09
to boost...@lists.boost.org
here, all the code , in bold i put the part where i call the client part tha have to connect to a server that is already listening open the same port, u will see some functions that are use for the simulator. I really aprecciate ur help. The strange thins is that i can connect to the same server using a external script, i mean, other code where simulator code is not included.
thanks

#include <stdio.h>
#include <stdlib.h>
#include "myNull.h"
#include "ip.h"
#include "udp.h"
#include "rtp.h"

#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/array.hpp>
#include <boost/numeric/conversion/cast.hpp>

#include <vector>
#include "connection.hpp" // Must come before boost/serialization headers.
#include <boost/serialization/vector.hpp>

#include <boost/lexical_cast.hpp>
#include <boost/thread/thread.hpp>
#include "stock.hpp"

static class myNullClass : public TclClass {
public:
        myNullClass() : TclClass("Agent/myNull") {}
        TclObject* create(int, const char*const*) {
                return (new myNull);
        }
}class_myNull;

namespace s11n_example {

/// Downloads stock quote information from a server.
class client
{
public:
  /// Constructor starts the asynchronous connect operation.
  client(boost::asio::io_service& io_service,
      const std::string& host, const std::string& service)
    : connection_(io_service)
  {
    // Resolve the host name into an IP address.
    boost::asio::ip::tcp::resolver resolver(io_service);
    boost::asio::ip::tcp::resolver::query query(host, service);
    boost::asio::ip::tcp::resolver::iterator endpoint_iterator =
      resolver.resolve(query);
    boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;

    // Start an asynchronous connect operation.
    connection_.socket().async_connect(endpoint,
        boost::bind(&client::handle_connect, this,
          boost::asio::placeholders::error, ++endpoint_iterator));
  }

  /// Handle completion of a connect operation.
  void handle_connect(const boost::system::error_code& e,
      boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
  {
    if (!e)
    {
      // Successfully established connection. Start operation to read the list
      // of stocks. The connection::async_read() function will automatically
      // decode the data that is read from the underlying socket.
//for(;;){     
connection_.async_read(stocks2_,
          boost::bind(&client::handle_read, this,
            boost::asio::placeholders::error));
    }
//}//cierra for
    else if (endpoint_iterator != boost::asio::ip::tcp::resolver::iterator())
    {
      // Try the next endpoint.
      connection_.socket().close();
      boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
      connection_.socket().async_connect(endpoint,
          boost::bind(&client::handle_connect, this,
            boost::asio::placeholders::error, ++endpoint_iterator));
    }
    else
    {
      // An error occurred. Log it and return. Since we are not starting a new
      // operation the io_service will run out of work to do and the client will
      // exit.
      std::cerr << e.message() << std::endl;
printf("error seccion cliente mynull \n");
    }
  }

  /// Handle completion of a read operation.
  void handle_read(const boost::system::error_code& e)
  {
    if (!e)
    {
      // Print out the data that was received.
printf("Cliente myNULL printing structure \n");
      for (std::size_t i = 0; i < stocks2_.size(); ++i)
      {printf(" jaja \n");
        std::cout << "Structura " << i << "\n";
        std::cout << " packet type: " << stocks2_[i].pkt_type << "\n";
        std::cout << "  packet id: " << stocks2_[i].id_pkt << "\n";
        std::cout << "  packet size: " << stocks2_[i].size_pkt << "\n";
        std::cout << "  IP origen: " << stocks2_[i].ip_src_addr << "\n";
        std::cout << "  IP destino: " << stocks2_[i].ip_dst_addr << "\n";
        std::cout << "  TTL: " << stocks2_[i].ttl << "\n";
        std::cout << "  Tiempo d envio: " << stocks2_[i].time << "\n";
       
      }
    }
   else
    {
      // An error occurred.
      std::cerr << e.message() << std::endl;
printf("error seccion cliente mynull ESTRUCTURA \n");
    }

    // Since we are not starting a new operation the io_service will run out of
    // work to do and the client will exit.
  }

private:
  /// The connection to the server.
  connection connection_;

  /// The data received from the server.
  std::vector<ns_pkt> stocks2_;
};



} // namespace s11n_example



void myNull::recv(Packet* pkt, Handler*)
{
       
//int i, j;
    printf("Entramos en myNull \n");
//sleep(4);
        //hdr_ip* iph=hdr_ip::access(pkt);
     
try
  {
  
//for(int i=1;i<8;i++){
    boost::asio::io_service io_service;
    s11n_example::client client(io_service, "localhost", "9999");
    io_service.run();
sleep(7);
  }

//}//end for
  catch (std::exception& e)
  {
    printf("Error myNull main-try \n");
std::cerr << e.what() << std::endl;
  }


    hdr_cmn* hdr=hdr_cmn::access(pkt);
    //hdr_rtp* rtp = hdr_rtp::access(pkt);
   
    pkt_received+=1;
       
    fprintf(tFile,"%-16f id %-16d udp %-16d\n", Scheduler::instance().clock(), hdr->uid_, hdr->size()-28);
       
    if (app_)
               app_->recv(hdr_cmn::access(pkt)->size());

        Packet::free(pkt);
}

int myNull::command(int argc, const char*const* argv)
{
    //Tcl& tcl = Tcl::instance();
   
    if (strcmp(argv[1], "set_filename") == 0) {
        strcpy(tbuf, argv[2]);
        tFile = fopen(tbuf, "w");
        return (TCL_OK);
    } 
   
    if (strcmp(argv[1], "closefile") == 0) {       
        fclose(tFile);
        return (TCL_OK);
    }
   
    if(strcmp(argv[1],"printstatus")==0) {
        print_status();
        return (TCL_OK);
    }
   
    return (Agent::command(argc, argv));
}

void myNull::print_status()
{
    printf("myEvalvid_Sink)Total packets received:%ld\n", pkt_received);
}

2009/10/20 Igor R <boost...@gmail.com>
yes, it is from a exception, i'm re-using the code on http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/example/serialization/client.cpp to implement a co-simulation framework using a famous simulator called network simulator 2, anyway , the runtime error comes when i try to do the connection with the server, the server is open in listening mode but i can not achieved establish the connection.
 
 
Can you post the exact code that you use to "establish the connection"?

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Igor R

unread,
Oct 20, 2009, 6:02:43 AM10/20/09
to boost...@lists.boost.org
try
  {
  
//for(int i=1;i<8;i++){
    boost::asio::io_service io_service;
    s11n_example::client client(io_service, "localhost", "9999");
    io_service.run();
sleep(7);
  }
 
 
 
Doesn't your debugger allow you to see what line of your code throws the exception?
Anyway, try to change "localhost" to "127.0.0.1" - maybe the resolver fails to resolve it.
Reply all
Reply to author
Forward
0 new messages