我正在使用具有以下配置的 crossbar.io 路由器,C++ 程序似乎卡在 session.join() 调用中。
{
"controller": {
},
"workers": [
{
"type": "router",
"realms": [
{
"name" : "thinqbot",
"permissions": [
{
"uri": "*",
"join" : true,
"publish": true,
"subscribe": true,
"call": true,
"register": true
}
]
}
],
"transports": [
{
"type": "web",
"endpoint":
{
"type": "tcp",
"port": 8080
},
"paths": {
"/": {
"type": "static",
"directory": ".."
},
"ws": {
"type": "websocket"
}
}
},
{
"type": "rawsocket",
"serializer" : "json",
"endpoint":
{
"type": "unix",
"path" : "/home/rk/router.sock"
}
},
{
"type": "rawsocket",
"serializer" : "json",
"endpoint":
{
"type": "tcp",
"port": 8082
}
}
]
}
]
}
对应的 C++ 代码。
int
main (int ac, char **av, char **env)
{
try
{
asio::io_service io;
tcp::socket socket(io);
tcp::resolver resolver(io);
auto endpoint_iterator = resolver.resolve({"127.0.0.1", "8082"});
bool debug = true;
autobahn::session<tcp::socket, tcp::socket> session(io, socket, socket, debug);
future<void> session_future;
std::cerr<<"\nTrying to connect to server ...";
boost::asio::async_connect(socket, endpoint_iterator,
[&](boost::system::error_code ec, tcp::resolver::iterator){
if(!ec){
std::cerr << "\nConnected to server" << endl;
session.start();
std::cerr<<"\nSession started.";
session_future = session.join("realm1").then([&](future<uint64_t> s){
std::cerr << "\nSession joined to realm with session ID " << s.get() << endl;
auto c0 = session.call("com.thinqbot.ping")
.then([](future<any> f){
std::cerr<<"\nping() invoked successfully";
});
c0.wait();
auto finish = when_all(std::move(c0));
finish.then([&](decltype(finish)){
session.publish("com.thinqbot.hello");
std::cerr<<"\nhello event published";
session.leave().then([&](future<string> reason){
std::cerr << "\nSession left [" << reason.get() << "]" << endl;
io.stop();
}).wait();
});
});
} else {
std::cerr << "\nCould not connect to server: " << ec.message() << endl;
}
}
);
io.run();
}
catch (std::exception& e)
{
std::cerr << e.what() << endl;
return 1;
}
return 0;
}
登录路由器。2014-09-15 14:05:31+0530 [控制器 3457] 日志已打开。
2014-09-15 14:05:31+0530 [控制器 3457] =============================== Crossbar.io = ==============================
2014-09-15 14:05:31+0530 [控制器 3457] Crossbar.io 0.9.7-6 开始
2014-09-15 14:05:31+0530 [Controller 3457] 自动选择最优Twisted reactor
2014-09-15 14:05:31+0530 [控制器 3457] 运行 Twisted reactor twisted.internet.epollreactor.EPollReactor
2014-09-15 14:05:31+0530 [控制器 3457] 使用 EPollReactor 反应器在 CPython 上运行
2014-09-15 14:05:31+0530 [控制器 3457] 从节点目录 /home/rk/work/wamp/.crossbar 开始
2014-09-15 14:05:31+0530 [控制器 3457] 从本地配置 '/home/rk/work/wamp/.crossbar/config.json' 开始
2014-09-15 14:05:31+0530 [控制器 3457] 在环境中未检测到 WAMPlet。
2014-09-15 14:05:31+0530 [控制器 3457] 启动 ID 为“worker1”的路由器 ..
2014-09-15 14:05:31+0530 [路由器 3460] 日志已打开。
2014-09-15 14:05:31+0530 [Router 3460] 使用 EPollReactor reactor 在 CPython 下运行
2014-09-15 14:05:31+0530 [路由器 3460] 进入事件循环..
2014-09-15 14:05:31+0530 [控制器 3457] ID 为“worker1”和 PID 3460 的路由器已启动
2014-09-15 14:05:31+0530 [控制器 3457] 路由器 'worker1': 领域 'realm1' 开始
2014-09-15 14:05:31+0530 [路由器 3460] 站点从 8080 开始
2014-09-15 14:05:31+0530 [控制器 3457] 路由器“worker1”:传输“transport1”开始
2014-09-15 14:05:31+0530 [路由器 3460] CrossbarWampRawSocketServerFactory 从 u'/home/rk/router.sock' 开始
2014-09-15 14:05:31+0530 [控制器 3457] 路由器“worker1”:传输“transport2”开始
2014-09-15 14:05:31+0530 [路由器 3460] CrossbarWampRawSocketServerFactory 从 8082 开始
2014-09-15 14:05:31+0530 [控制器 3457] 路由器“worker1”:传输“transport3”开始