本文整理汇总了C++中client类的典型用法代码示例。如果您正苦于以下问题:C++ client类的具体用法?C++ client怎么用?C++ client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_bitcount
void test_bitcount(client &c) {
c.flushdb();
c.set("mykey", "foobar");
assert(c.bitcount("mykey")==26);
assert(c.bitcount("mykey", {0,0})==4);
assert(c.bitcount("mykey", {1,1})==6);
assert(c.bitcount("nonexist", {8,12})==0);
}
示例2: echoMessage
void echoMessage(int i)
{
echoed = false;
clientIO.send(heavyConnections[i], ECHO_MESSAGE, websocketpp::frame::opcode::value::TEXT);
while(!echoed) {
clientIO.run_one();
}
}
示例3: nextConnection
void nextConnection()
{
static std::string uri;
if (connections % CONNECTIONS_PER_INTERFACE == 0) {
uri = "ws://127.0.0." + to_string(connections / CONNECTIONS_PER_INTERFACE + 1) + ":" + to_string(port);
}
websocketpp::lib::error_code ec;
connection_ptr con = clientIO.get_connection(uri, ec);
clientIO.connect(con);
}
示例4: main
int main(int argc, char **argv)
{
clientIO.clear_access_channels(websocketpp::log::alevel::all);
clientIO.init_asio();
clientIO.set_message_handler([](websocketpp::connection_hdl hdl, client::message_ptr msg) {
if (ECHO_MESSAGE != msg->get_payload()) {
cout << "Error echo" << endl;
exit(-1);
}
echoed = true;
});
clientIO.set_open_handler([&clientIO](websocketpp::connection_hdl hdl) {
connected = true;
heavyConnections.push_back(hdl);
});
startPoint = chrono::system_clock::now();
while(connections < TOTAL_CONNECTIONS) {
// Idle connections are made very lightweight
for (int i = 0; i < IDLE_CONNECTIONS_PER_ACTIVE_CONNECTION
&& connections < TOTAL_CONNECTIONS; i++) {
if (nextLightweightConnection()) {
return -1;
}
}
// Active connections are "real" using WebSocket++
nextHeavyweightConnection();
}
cout << "----------------------------------" << endl;
cout << "Active connections: " << heavyConnections.size() << endl;
cout << "Idle connections: " << (connections - heavyConnections.size()) << endl;
float connectionsPerSecond = float(connections) / chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - startPoint).count();
cout << "Connection performance: " << connectionsPerSecond << " connections/ms" << endl;
// start sending messages using the active connections
cout << "----------------------------------" << endl;
startPoint = chrono::system_clock::now();
for (int i = 0; i < heavyConnections.size(); i++) {
echoMessage(i);
}
cout << "Echo delay, microseconds: " << chrono::duration_cast<chrono::microseconds>(chrono::system_clock::now() - startPoint).count() << endl;
cout << "ALL DONE" << endl;
clientIO.run();
return 0;
}
示例5: run_time_limited_client
void run_time_limited_client(client & c, std::string uri, long timeout,
bool log)
{
if (log) {
c.set_access_channels(websocketpp::log::alevel::all);
c.set_error_channels(websocketpp::log::elevel::all);
} else {
c.clear_access_channels(websocketpp::log::alevel::all);
c.clear_error_channels(websocketpp::log::elevel::all);
}
c.init_asio();
websocketpp::lib::error_code ec;
client::connection_ptr con = c.get_connection(uri,ec);
BOOST_CHECK( !ec );
c.connect(con);
websocketpp::lib::thread tthread(websocketpp::lib::bind(
&close_after_timeout<client>,
websocketpp::lib::ref(c),
con->get_handle(),
timeout
));
tthread.detach();
c.run();
}
示例6: nextHeavyweightConnection
void nextHeavyweightConnection()
{
connected = false;
string uri = "ws://127.0.0." + to_string(address) + ":" + to_string(PORT);
websocketpp::lib::error_code ec;
connection_ptr con = clientIO.get_connection(uri, ec);
clientIO.connect(con);
while(!connected) {
clientIO.run_one();
}
updateAddress();
}
示例7: test_sub
void test_sub(client &c) {
message_queue &q=c.subscribe({"abc", "def"});
fiber pubber(test_pub);
redis_message msg;
q.pop(msg);
assert(msg.first=="abc");
assert(msg.second=="123");
q.pop(msg);
assert(msg.first=="def");
assert(msg.second=="456");
c.unsubscribe({"abc", "def"});
this_fiber::sleep_for(std::chrono::seconds(1));
assert(!q.is_open());
pubber.join();
}
示例8: test_get_set
void test_get_set(client &c) {
c.flushdb();
c.set("k1", "v1");
assert(*c.get("k1")=="v1");
c.set("k1", "v2");
assert(*c.get("k1")=="v2");
assert(!c.get("nonexist"));
c.set("mykey", "10.5");
c.incrbyfloat("mykey", "0.1");
assert(*(c.get("mykey"))=="10.6");
}
示例9: async_submit_job
inline error_code async_submit_job(client const &client, char const *rsl, JobSubmitCallback const &job_submit_callback, int state_mask, StateChangeCallback const &state_chage_callback)
{
typedef listen_state_op<StateChangeCallback, non_blocking> listen_state_op_type;
listen_state_op_type *listener_op = new listen_state_op_type(state_chage_callback);
char *callback_contact(0);
int const callback_allowed(
::globus_gram_client_callback_allow(
&listen_state_op<StateChangeCallback, non_blocking>::callback,
listener_op, &callback_contact));
if (callback_allowed != GLOBUS_SUCCESS)
{
delete listener_op;
return static_cast<error_code>(callback_allowed);
}
job_submit_op<JobSubmitCallback> *op = new job_submit_op<JobSubmitCallback>(job_submit_callback);
int const job_requested(
::globus_gram_client_register_job_request(
client.contact(), rsl, state_mask, callback_contact, 0, &job_submit_op<JobSubmitCallback>::callback, op));
if (job_requested != GLOBUS_SUCCESS)
{
delete listener_op;
delete op;
return static_cast<error_code>(job_requested);
}
return no_error;
}
示例10: submit_job_wait_until
inline error_code submit_job_wait_until(client const &client, char const *rsl, int state_mask, StateChangeListener const &listener)
{
listen_state_op<StateChangeListener, blocking> listener_op(listener);
char *callback_contact(0);
int const callback_allowed(
::globus_gram_client_callback_allow(
&listen_state_op<StateChangeListener, blocking>::callback,
&listener_op, &callback_contact));
if (callback_allowed != GLOBUS_SUCCESS) return static_cast<error_code>(callback_allowed);
listener_op.listen();
char *job_contact(0);
int const job_requested(
::globus_gram_client_job_request(
client.contact(), rsl, state_mask, callback_contact, &job_contact));
if (job_requested != GLOBUS_SUCCESS)
{
listener_op.cancel();
return static_cast<error_code>(job_requested);
}
typedef std::pointer_to_unary_function<void *,void> function_type;
globus::util::on_exit<function_type> free_contact(
std::ptr_fun(::free), job_contact);
return no_error;
}
示例11: on_message
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
client::connection_ptr con = sip_client.get_con_from_hdl(hdl);
std::cout << "Received a reply:" << std::endl;
fwrite(msg->get_payload().c_str(), msg->get_payload().size(), 1, stdout);
received=true;
}
示例12: test_sscan
void test_sscan(client &c) {
c.flushdb();
std::set<std::string> expected;
for (int i=42; i<442; i++) {
std::string k("key");
k+=boost::lexical_cast<std::string>(i);
c.sadd("myset", {k});
expected.insert(k);
}
std::set<std::string> keys;
for(auto i=c.sscan("myset"); i!=c.end(); ++i) {
keys.insert(*i);
}
assert(keys==expected);
}
示例13: test_zscan
void test_zscan(client &c) {
c.flushdb();
std::set<std::string> expected;
for (int i=42; i<442; i++) {
std::string k("key");
k+=boost::lexical_cast<std::string>(i);
c.zadd("myzset", {{1.2, k}});
expected.insert(k);
}
std::set<std::string> keys;
for(auto i=c.zscan("myzset"); i!=c.end(); ++i) {
keys.insert(*i);
assert(i.score()==1.2);
}
assert(keys==expected);
}
示例14: test_hscan
void test_hscan(client &c) {
c.flushdb();
std::set<std::string> expected;
for (int i=42; i<442; i++) {
std::string k("key");
k+=boost::lexical_cast<std::string>(i);
std::string v("key");
v+=boost::lexical_cast<std::string>(i);
c.hset("myhash", k, v);
expected.insert(k);
}
std::set<std::string> keys;
for(auto i=c.hscan("myhash"); i!=c.end(); ++i) {
keys.insert(*i);
}
assert(keys==expected);
}
示例15: on_open
void on_open(client* c, websocketpp::connection_hdl hdl) {
// now it is safe to use the connection
std::cout << "connection ready" << std::endl;
received=false;
// Send a SIP OPTIONS message to the server:
std::string SIP_msg="OPTIONS sip:[email protected] SIP/2.0\r\nVia: SIP/2.0/WS df7jal23ls0d.invalid;rport;branch=z9hG4bKhjhs8ass877\r\nMax-Forwards: 70\r\nTo: <sip:car[email protected]>\r\nFrom: Alice <sip:[email protected]>;tag=1928301774\r\nCall-ID: a84b4c76e66710\r\nCSeq: 63104 OPTIONS\r\nContact: <sip:[email protected]>\r\nAccept: application/sdp\r\nContent-Length: 0\r\n\r\n";
sip_client.send(hdl, SIP_msg.c_str(), websocketpp::frame::opcode::text);
}