我需要比较两个websocket ++ connection_hdl:
// Create a weak pointer on the heap using that shared_ptr.
// Cast that weak pointer to void* and manage it using another shared_ptr
// connection_hdl hdl(reinterpret_cast<void*>(new connection_weak_ptr(con)));
Run Code Online (Sandbox Code Playgroud)
我试过这段代码
template <typename T, typename U>
inline bool equals(const connection_hdl<T>& t, const connection_hdl<U>& u)
{
return !t.owner_before(u) && !u.owner_before(t);
}
Run Code Online (Sandbox Code Playgroud)
但编译器抱怨说connection_hdl is not a template.
可以修改上面的代码来比较connection_hdls吗?connection_hdls可以通过使用owner_less与容器一起使用,所以在我缺乏经验的情况下,可以使用所有权来进行比较.
我能找到的唯一其他相关技术是比较weak_ptrs集
bool result = !(std::lexicographical_compare(set1.begin(), set1.end(),
set2.begin(), set2.end(),
set1.value_comp()) ||
std::lexicographical_compare(set2.begin(), set2.end(),
set1.begin(), set1.end(),
set1.value_comp()));
Run Code Online (Sandbox Code Playgroud)
这似乎与我的需求很接近,但由于我的经验不足,我不能确定或修改那些符合我意图的代码. …
当使用带有ASIO模式的Websocket ++时,我开始连接:
boost::shared_ptr<client> x(new client());
x->init_asio();
websocketpp::lib::error_code ec;
client::connection_pt con = x->get_connection(url, ec);
x->connect(con);
new thread(boost::bind(&LocalCallbacks::run, x)); // which just runs x->run()
Run Code Online (Sandbox Code Playgroud)
从提供的示例中复制(带有修改)此模式.当用户按下按钮取消websocket时,我应该如何正确清理?我目前在做:
x->stop();
Run Code Online (Sandbox Code Playgroud)
我也应该打电话x->close()吗?在打电话close之前我是否需要等待stop?我是否需要杀死thread已创建的内容,还是会自动停止?我有关于当前代码离开websocket会话的报告.
有没有办法用websocket ++ 0.3X跟踪每个用户数据?
我希望能够识别它们,以便跟踪它们正在查看的内容以及应该发送给它们的内容.以堆栈作为一个例子:当你在看这个问题,一个可能的WebSocket(我认为不会)保存在内存中,你在看这个问题,并给你喜欢的投票,新的意见和答案相应的更新,并StackExchange在左上角更新.
此外,用户需要能够识别.websocket中是否存在固有的会话ID已经隐藏在websocket ++中?如果没有,websocket ++如何跟踪用户?
我需要快速,安全和便携的websockts所以我一直在互联网上挖掘,我遇到了Zaphoyd Studios的 WebSocket ++ .
我有零c ++经验(虽然我是一名熟练的程序员)但它似乎勾选了我需要的每一个盒子,我很快在github上调整了echo_server和telemetry_client示例,并将概念证明放在一起.
设置我的手到wss服务器示例(echo_server_tls)我快速编译并使用一个简单的测试客户端来验证它是否正常工作.
不幸的是,我的经验不足以使我失望,我天真地希望将url更改为wss并包含tls启用的客户端头文件(asio_client.hpp而不是asio_no_tls_client.hpp)会让我朝着正确的方向前进!
它不会,而是给出错误; -
[2014-05-29 01:17:58] [application] Get Connection Error: endpoint not secure
Run Code Online (Sandbox Code Playgroud)
所以...我的问题; -
有没有人有一个"echo_client_tls"的例子,因为它让我朝着正确的方向前进,我非常怀疑我是第一个这样做的人(也许只是最缺乏经验的c ++).
我相信我可以从那里拿走它(我甚至会把它提交给git,因为它可能对我自己的其他新手很有用).
PS Kudos如果他们读过这篇文章的作者,那么它似乎是一个非常完整的实现!
是否可以在同时使用 IPv4 和 IPv6 的双栈环境中测试 IP 地址的等效性?如果是这样,如何?
我的应用程序在 Boost ASIO 之上使用websocket++。
例如,在我的 LAN 上,一个应用程序连接到另一个侦听192.168.1.2,但使用此答案的 IP 地址获取器
std::string s = socket.remote_endpoint().address().to_string();
Run Code Online (Sandbox Code Playgroud)
给::ffff:192.168.1.3作为客户的地址。
问题是.2它将拥有自己的节点列表,其中包含原始 v4 地址 for .3,因此通过上面的 getter 与磁盘上保存的 v4 版本的简单字符串比较,.3即使已经连接,它也会寻找冗余连接。
我进一步读到事情可能会变得更加复杂,因为通过这个点分四元表示法,::ffff:192.0.2.128也是::ffff:c000:0280.
我正在构建一个接受来自不受信任来源的地址的 p2p 应用程序,因此为了防止冗余连接,我需要能够绝对测试等效性。
我的意图可以实现吗?如果是这样,如何?如果没有,我应该只使用 v4 吗?我宁愿现在就包含未来的功能,而不是担心以后的集成。
我正在调试一些使用websocketpp的外部代码。尽管一切正常,但我一直在获得相当详细的控制台输出。我可以禁用输出还是至少指向特定的东西?BR,丹尼尔
[2014-07-08 14:51:27] [fatal] error in handle_read_handshake: End of File
[2014-07-08 14:51:27] [fatal] error in handle_read_frame: End of File (websocketpp.transport:7)
[2014-07-08 14:51:27] [info] asio async_shutdown error: system:10054 (An existing connection was forcibly closed by the remote host)
[2014-07-08 14:51:27] [error] Underlying Transport Error
[2014-07-08 14:51:27] [fatal] error in handle_read_frame: End of File (websocketpp.transport:7)
[2014-07-08 14:51:27] [info] asio async_write error: system:10053 (An established connection was aborted by the software in your host machine)
[2014-07-08 14:51:27] [fatal] error in handle_write_frame: Underlying TransportError …Run Code Online (Sandbox Code Playgroud) Zaphoyd broadcast_server.cpp看起来像是websocket服务器的完美骨干,它可以快速接受并发送消息和连接与线程进行实际操作,从而不会中断通信. https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp
他的简单print_server.cpp例子很容易编译; 但是,我得到了一些编译错误broadcast_server.cpp.
root@server:~# g++ -O3 broadcast_server.cpp -I ~/websocketpp-experimental/ -lboost_system
broadcast_server.cpp:126:37: error: 'owner_less' is not a member of 'std'
broadcast_server.cpp:126:37: error: 'owner_less' is not a member of 'std'
broadcast_server.cpp:126:70: error: 'con_list' was not declared in this scope
broadcast_server.cpp:126:70: error: template argument 2 is invalid
broadcast_server.cpp:126:18: warning: 'typedef' was ignored in this declaration [enabled by default]
broadcast_server.cpp:129:5: error: 'con_list' does not name a type
broadcast_server.cpp: In member function 'void broadcast_server::process_messages()':
broadcast_server.cpp:109:17: error: 'm_connections' was …Run Code Online (Sandbox Code Playgroud) 我正在研究Ubuntu,我正在编写一个使用websocket ++库的c ++服务器,它非常适合来自浏览器的传入websocket连接(我在那里使用javascript).
现在我想做一些性能测试并连接很多自动化的'假'客户端.
为此,我想编写一个多次启动并连接到该服务器的程序.为此,我尝试了以下代码:
#include "websocketpp/src/roles/client.hpp"
#include "websocketpp/src/websocketpp.hpp"
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include "FakeClient.h"
using boost::asio::ip::tcp;
using websocketpp::client;
FakeClient::FakeClient()
{
thisPointer = boost::shared_ptr<FakeClient>(this);
client endpoint(thisPointer);
endpoint.alog().unset_level(websocketpp::log::alevel::ALL);
endpoint.elog().unset_level(websocketpp::log::elevel::ALL);
endpoint.elog().set_level(websocketpp::log::elevel::RERROR);
endpoint.elog().set_level(websocketpp::log::elevel::FATAL);
endpoint.connect("ws://localhost:9001/");
boost::thread t(&FakeClient::run, *this);
t.join();
}
void FakeClient::run()
{
while(true)
{
// send stuff here
usleep(100);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当服务器启动并且假客户端尝试连接时,我只会收到以下错误:
2013-04-23T16:00:02 [2] fail_on_expire timer expired with message: Timeout on WebSocket handshake
Run Code Online (Sandbox Code Playgroud)
但是,当服务器未启动时,不会显示任何错误消息,因此肯定会发生某种连接.但我无法弄清楚我做错了什么.是否可以通过websocket ++ lib轻松连接2个二进制程序?
为了获得最佳性能测试结果,我认为应该使用websockets进行服务器和假客户端之间的通信.
谢谢您的帮助,
Koonschi
我使用优秀的websocketpp库在C++应用程序中提供Websockets(和HTTP)服务器.我还需要在同一个应用程序中的HTTP客户端连接到REST API.我也一直在websocketpp尝试这个,但到目前为止我没有成功.以下初步尝试为我提供了这个日志输出:
[2015-03-06 18:01:18] [connect] Successful connection
[2015-03-06 18:01:18] [error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)
[2015-03-06 18:01:18] [disconnect] Failed: Invalid HTTP status.
Run Code Online (Sandbox Code Playgroud)
这表明我的http_处理程序方法可能需要更多.任何意见,将不胜感激.websocketpp文档和示例似乎不包含简单的HTTP客户端.
#define _WEBSOCKETPP_CPP11_STL_
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>
#include <websocketpp/common/thread.hpp>
namespace {
using namespace websocketpp;
typedef client<websocketpp::config::asio_client> client;
class Client {
public:
Client(void){
client_.init_asio();
client_.set_http_handler(bind(&Client::http_,this,_1));
}
std::string get(const std::string& url) {
websocketpp::lib::error_code error;
client::connection_ptr con = client_.get_connection(url,error);
if(error) std::runtime_error("Unable to connnect.\n url: "+url+"\n message: "+error.message());
client_.connect(con);
websocketpp::lib::thread asio_thread(&client::run, &client_);
asio_thread.join();
return data_; …Run Code Online (Sandbox Code Playgroud) 我无法通过名为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 …Run Code Online (Sandbox Code Playgroud) 我已经构建了一个非常基本的EXE,它使用Websocketpp客户端,它只连接到Websocket服务器,并发送和接收消息.我用过VS 2013.
我注意到EXE的大小是巨大的.它类似于2.3 MB的Release和6 MB的Debug.
关于如何减小EXE大小的任何想法?
我真的是 websocketpp 的新手。你能告诉我,如何在我的服务器中的新连接上获取 websocket 连接路径吗?我的意思是我需要得到这个部分:
ws://localhost:8080/addr1 ------> get addr1
ws://localhost:8080/addr2 ------> get addr2
ws://localhost:8080/etc ------> get etc
Run Code Online (Sandbox Code Playgroud)
我现在使用此链接中的示例:http://www.zaphoyd.com/websocketpp/manual/common-patterns/storing-connection-specificsession-information
websocket++ ×12
c++ ×10
websocket ×5
boost ×2
boost-asio ×2
c++11 ×1
comparison ×1
equivalence ×1
ip-address ×1
member ×1
sessionid ×1
ssl ×1
std ×1
stl ×1
weak-ptr ×1
wss ×1