Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does boost::asio appear to do nothing
    text
    copied!<p>I'm trying to implement the irc protocol in a very basic manner. My first attempt is to use boost::asio and connect to a server and read the motd. AFAIK the motd is sent to every client when they connect. I have made the following test program and it seems to not do anything. It's not a very good piece of code but this is all I have after several frustrating hours.</p> <pre><code>#define _WIN32_WINNT 0x0501 #include &lt;iostream&gt; #include &lt;boost/asio.hpp&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/function.hpp&gt; #include &lt;queue&gt; class IrcConnection { public: IrcConnection(const std::string&amp; server, int port, boost::function&lt;void (const std::string&amp;)&gt; onMessage, boost::asio::io_service&amp; io_service): s(server), p(port), onM(onMessage), ios(io_service), socket(io_service) { } void connect() { somethingHappened = false; //DNS stuff boost::asio::ip::tcp::resolver resolver(ios); boost::asio::ip::tcp::resolver::query query(s , "0"); boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(query); boost::asio::ip::tcp::resolver::iterator end; boost::system::error_code error; while(iter != end) { boost::asio::ip::tcp::endpoint endpoint = iter-&gt;endpoint(); endpoint.port(p); socket.close(); socket.connect(endpoint, error); iter++; } if(error) { std::cout &lt;&lt; "ERROR" &lt;&lt; std::endl; std::cout &lt;&lt; error &lt;&lt; std::endl; } std::cout &lt;&lt; "Connected to: " &lt;&lt; socket.remote_endpoint().address().to_string() &lt;&lt; std::endl; //read from the socket until a space is found boost::asio::async_read_until(socket, currentData, ' ', boost::bind(&amp;IrcConnection::onReceiveFinished, this, boost::asio::placeholders::error)); } void disconnect() { socket.close(); } void send(int priority, const std::string&amp; message) { } bool somethingHappened; private: std::string s; int p; boost::function&lt;void (const std::string&amp;)&gt; onM; boost::asio::io_service&amp; ios; boost::asio::ip::tcp::socket socket; std::priority_queue&lt;std::string&gt; outQueue; boost::asio::streambuf currentData; void onReceiveFinished(const boost::system::error_code&amp; error) { if(error) { disconnect(); std::cout &lt;&lt; "ERRORRRR" &lt;&lt; std::endl; std::cout &lt;&lt; error &lt;&lt; std::endl; } std::cout &lt;&lt; "STUFF IS OCCURING" &lt;&lt; std::endl; somethingHappened = true; std::istream stream(&amp;currentData); std::string data; std::getline(stream, data); boost::asio::async_read_until(socket, currentData, ' ', boost::bind(&amp;IrcConnection::onReceiveFinished, this, boost::asio::placeholders::error)); ios.dispatch(boost::bind(onM, data)); } }; void onMe(const std::string&amp; x) { std::cout &lt;&lt; "MESSAGE" &lt;&lt; std::endl; std::cout &lt;&lt; x &lt;&lt; std::endl; } int main() { boost::asio::io_service ios; std::string server = "irc.efnet.org"; int port = 6667; IrcConnection x(server, port, onMe, ios); x.connect(); while(!x.somethingHappened) { // } return 0; } </code></pre> <p>The program attempts to connect to irc.efnet.org and read until a space is sent and then spits that data out to the terminal. However I run this and all that is printed is the ip address of what I connected to and then the program does not terminate.</p> <p>What do I need to do to get my indented behavior?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload