websocketppという名前の WebSockets C++ ライブラリ経由で MtGox API から情報を取得できません:
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>
#include <iostream>
typedef websocketpp::client<websocketpp::config::asio_client> client;
using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
void on_open(websocketpp::connection_hdl hdl)
{
std::cout << "on_open \n";
}
void on_close(websocketpp::connection_hdl hdl)
{
std::cout << "on_close \n";
}
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg)
{
std::cout << msg->get_payload() << '\n';
}
int main()
{
client c;
try
{
c.init_asio();
c.set_open_handler(on_open);
c.set_close_handler(on_close);
c.set_message_handler(bind(&on_message, &c, ::_1, ::_2));
websocketpp::lib::error_code ec;
client::connection_ptr con = c.get_connection("ws://websocket.mtgox.com:80/mtgox?Currency=EUR", ec);
c.connect(con);
c.run();
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
catch (websocketpp::lib::error_code e)
{
std::cout << e.message() << std::endl;
}
catch (...)
{
std::cout << "other exception" << std::endl;
}
}
出力
[2013-11-18 23:10:10] [接続] 接続成功
[2013-11-18 23:10:14] [エラー] サーバー ハンドシェイクの応答が無効でした: HTTP ステータスが無効です。
[2013-11-18 23:10:14] [切断] 失敗: 無効な HTTP ステータス。
デバッガーで「403 禁止」エラーが表示されますが、http://www.websocket.org/echo.htmlなどのサービスを介して使用できます。
「ws://socketio.mtgox.com:80/mtgox?Currency=EUR」を使用しようとしましたが、次のエラーが表示されました。
[2013-11-18 23:18:07] [接続] 接続成功
[2013-11-18 23:18:08] [エラー] handle_read_http_response のエラー: ファイルの終わり
[2013-11-18 23:18:08] [切断] 失敗: ファイルの終わり
このコードの何が問題になっていますか?