Boost.Asio に苦戦中

boost::asio::ip::tcp::iostream の接続エラー内容って
Windows では GetLastError() でしかとれないのかな?


接続エラーかどうかの判断は good() と fail() ?


【Client】

#include <iostream>

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif

#include <boost/asio.hpp>

using namespace std;
using namespace boost::asio;
using ip::tcp;

int main()
{
    io_service io;

    // 接続(IP, Port)
    tcp::iostream s("127.0.0.1", "31400");

    cout << GetLastError() << endl; // 2...指定されたファイルが見つかりません。
//  cout << s.good() << endl; // 0
//  cout << s.fail() << endl; // 1

    // 送信
    s << "Hello";
    s.flush();

    return 0;
}


【Server】

#include <iostream>
#include <string>

#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif

#include <boost/asio.hpp>

using namespace std;
using namespace boost::asio;
using ip::tcp;

int main()
{
    io_service io;

    tcp::acceptor acc(io, tcp::endpoint(tcp::v4(), 31400));

    for (;;) {
        // 接続待ち
        tcp::iostream s;
        acc.accept(*s.rdbuf());

        cout << "[connect start]" << endl;

        // 受信
        string line;
        while (getline(s, line)) {
            cout << line << endl;
        }

        cout << "[connect end]" << endl;
    }

    return 0;
}
[connect start]
[connect end]


うーむ・・・こうなってほしいんだけど

[connect start]
Hello
[connect end]


ローカルで接続してるのになんでつながらないんだろ

サーバー側からはつながってるように見えるんだけどなー



ちなみに telnet ではちゃんとつながる

telnet 127.0.0.1 31400