Boost logo

Boost Users :

Subject: [Boost-users] [asio] Clients (try to) connect only once
From: Jens Weller (JensWeller_at_[hidden])
Date: 2009-02-10 10:30:05


Hi I am writing on a an app, that has clients, which connect, and get events/updates send.

Now, it works almost, but still, I got one problem I couldn't solve sofar:
My Client only connects or tries to connect once. If the server isn't running, I have to restart the app, to be able to try again.
I do get a connection event at the server, but the client seems not to respond to the send data afterwards.

I am not sure, if it might be a threading issue, but i think that calling join() should do the job.

My Code:

void ZMSRClientFrame::OnConnect(wxCommandEvent& event)
{
    // the behavoir happens also with out those 2 ifs (just tried to check that)
    if(inputhandler)
    {
        inputhandler->close();
    }
    if(t)
    {

        t->join();
        t.reset();
    }
    try{
        boost::asio::ip::tcp::resolver resolver(ios);
        boost::asio::ip::tcp::resolver::query query("127.0.0.1", "3210");
        boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);

        //InputHandler in(ios,iterator);
        inputhandler = boost::shared_ptr<InputHandler>(new InputHandler(this,ios,iterator));
        //ios.run();
        //starting ioservice thread
        t = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&boost::asio::io_service::run, &ios)));
    }
    catch(std::exception& e)
    {
        wxMessageBox(e.what());
        //inputhandler.reset();
    }
    catch(...)
    {wxMessageBox("could not connect");
    //inputhandler.reset();
    }
}

Inputhandler calls async_connect which returns to one of its members. Which works through the first run.

How to solve this?

regards

Jens Weller

-- 
Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

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