我正在使用具有以下配置的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 [Controller 3457] ============================== Crossbar .io ==============================
2014-09-15 14:05:31 + 0530 [Controller 3457] Crossbar.io 0.9.7-6开始
2014-09-15 14:05:31 + 0530 [控制器3457]自动选择最佳扭曲反应器
2014-09-15 14:05:31 + 0530 [Controller 3457]运行Twisted reactor twisted.internet.epollreactor.EPollReactor
2014-09-15 14:05:31 + 0530 [Controller 3457]使用EPollReactor reactor在CPython上运行
2014-09-15 14:05:31 + 0530 [Controller 3457]从节点目录/home/rk/work/wamp/.crossbar开始
2014-09-15 14:05:31 + 0530 [Controller 3457]从本地配置开始&#39; /home/rk/work/wamp/.crossbar/config.json'
2014-09-15 14:05:31 + 0530 [Controller 3457]在环境中未检测到WAMPlet。
2014-09-15 14:05:31 + 0530 [Controller 3457]使用ID&#39; worker1&#39;启动路由器..
2014-09-15 14:05:31 + 0530 [Router 3460]登录日志。
2014-09-15 14:05:31 + 0530 [Router 3460]使用EPollReactor reactor在CPython下运行
2014-09-15 14:05:31 + 0530 [Router 3460]进入事件循环..
2014-09-15 14:05:31 + 0530 [Controller 3457] ID为&#39; worker1&#39;的路由器和PID 3460开始
2014-09-15 14:05:31 + 0530 [Controller 3457]路由器&#39; worker1&#39;:领域&#39; realm1&#39;开始
2014-09-15 14:05:31 + 0530 [Router 3460]网站从8080开始
2014-09-15 14:05:31 + 0530 [Controller 3457]路由器&#39; worker1&#39 ;: transport&#39; transport1&#39;开始
2014-09-15 14:05:31 + 0530 [Router 3460] CrossbarWampRawSocketServerFactory起始于&#39; /home/rk/router.sock'
2014-09-15 14:05:31 + 0530 [Controller 3457]路由器&#39; worker1&#39 ;: transport&#39; transport2&#39;开始
2014-09-15 14:05:31 + 0530 [Router 3460] CrossbarWampRawSocketServerFactory从8082开始
2014-09-15 14:05:31 + 0530 [Controller 3457]路由器&#39; worker1&#39 ;: transport&#39; transport3&#39;开始
答案 0 :(得分:0)
客户端和路由器之间存在序列化不匹配,路由器期待json和客户端发送msgpack。使用C ++客户端时,需要将序列化程序更改为msgpack。需要安装Crossbar msgpack序列化程序。请在配置中的传输节中添加&#34; debug&#34;:true以获得更详细的错误报告。