[asio][iostream] trying to implement nntp-client
Hi Boosters, I´m playing around with the great boost::asio library but have problems using the boost::asio::ip::tcp::iostream. I try to implement a very simple nntp-client: <code> void connect_and_retrieve_list_of_newsgroups() { std::string line; // connect to server boost::asio::ip::tcp::iostream s("news.gmane.org", "nntp"); if (!s) return; // read connection ack std::getline(s, line); // log std::cout << line; // check return code here. we assume everything is fine. // ... // send LIST command to request a list of newsgroups (see rfc 977) // the server will respond with one or more lines s << "LIST\r\n"; // read response std::getline(s, line); // <-- waits here 'til server timeout ... } </code> For some reason I don't get a response to the LIST command. After a few minutes of waiting the server send a timeout notification. It is like I had never sent the request. The same code using sockets and asio::write() works ok. So my questions are: - In what way differ tcp::iostreams sending from asio::write() sending? - Do tcp::iostreams append (or convert or drop) any characters of the given string before sending? - Is there a way to gain direct access to tcp::iostreams underlying socket (at least for testing)? - What am I doing wrong? Any help would be much appreciated! Cheers Sascha
Sascha Seewald wrote:
Hi Boosters,
I´m playing around with the great boost::asio library but have problems using the boost::asio::ip::tcp::iostream.
I try to implement a very simple nntp-client:
<code>
void connect_and_retrieve_list_of_newsgroups() {
std::string line;
// connect to server boost::asio::ip::tcp::iostream s("news.gmane.org", "nntp"); if (!s) return;
// read connection ack std::getline(s, line);
// log std::cout << line;
// check return code here. we assume everything is fine. // ...
// send LIST command to request a list of newsgroups (see rfc 977) // the server will respond with one or more lines s << "LIST\r\n";
Try adding s.flush() here.
// read response std::getline(s, line); // <-- waits here 'til server timeout
... }
</code>
For some reason I don't get a response to the LIST command. After a few minutes of waiting the server send a timeout notification. It is like I had never sent the request. The same code using sockets and asio::write() works ok.
So my questions are: - In what way differ tcp::iostreams sending from asio::write() sending? - Do tcp::iostreams append (or convert or drop) any characters of the given string before sending? - Is there a way to gain direct access to tcp::iostreams underlying socket (at least for testing)? - What am I doing wrong?
Any help would be much appreciated!
Cheers Sascha
Jakub Stachowski wrote:
Sascha Seewald wrote:
Hi Boosters,
I´m playing around with the great boost::asio library but have problems using the boost::asio::ip::tcp::iostream.
I try to implement a very simple nntp-client:
<code>
void connect_and_retrieve_list_of_newsgroups() {
std::string line;
// connect to server boost::asio::ip::tcp::iostream s("news.gmane.org", "nntp"); if (!s) return;
// read connection ack std::getline(s, line);
// log std::cout << line;
// check return code here. we assume everything is fine. // ...
// send LIST command to request a list of newsgroups (see rfc 977) // the server will respond with one or more lines s << "LIST\r\n";
Try adding s.flush() here.
Yeah, that worked! Many Thanks! Sascha
participants (2)
-
Jakub Stachowski
-
Sascha Seewald