您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ zmq_bind函数代码示例

51自学网 2021-06-03 12:00:53
  C++
这篇教程C++ zmq_bind函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中zmq_bind函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_bind函数的具体用法?C++ zmq_bind怎么用?C++ zmq_bind使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了zmq_bind函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char *argv[]){    zmq::context_t context(1);    //  Socket facing clients    zmq::socket_t frontend (context, ZMQ_ROUTER);    frontend.bind("tcp://*:5559");    //  Socket facing services    zmq::socket_t backend (context, ZMQ_DEALER);    zmq_bind (static_cast<void *>(backend), "tcp://*:5560");    //  Start built-in device    zmq_device (            ZMQ_QUEUE,            static_cast<void *>(frontend),            static_cast<void *>(backend)            );    return 0;}
开发者ID:fifilyu,项目名称:zguide-examples-cpp-with-cmake,代码行数:20,


示例2: agent_control_message

static voidagent_control_message (agent_t *self){    zmsg_t *msg = zmsg_recv (self->pipe);    char *method = zmsg_popstr (msg);    if (streq (method, "BIND")) {        char *endpoint = zmsg_popstr (msg);        assert (endpoint);        int rc = zmq_bind (self->router, endpoint);        assert (rc == 0);        free (endpoint);    }    else    if (streq (method, "STOP")) {        zstr_send (self->pipe, "OK");        self->stopped = true;    }    free (method);    zmsg_destroy (&msg);}
开发者ID:AlexGiovanentti,项目名称:zguide,代码行数:20,


示例3: test_basic

void test_basic (){    size_t len = MAX_SOCKET_STRING;    char my_endpoint[MAX_SOCKET_STRING];    void *router = test_context_socket (ZMQ_ROUTER);    TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router, "tcp://127.0.0.1:*"));    TEST_ASSERT_SUCCESS_ERRNO (      zmq_getsockopt (router, ZMQ_LAST_ENDPOINT, my_endpoint, &len));    //  Send a message to an unknown peer with the default setting    //  This will not report any error    send_string_expect_success (router, "UNKNOWN", ZMQ_SNDMORE);    send_string_expect_success (router, "DATA", 0);    //  Send a message to an unknown peer with mandatory routing    //  This will fail    int mandatory = 1;    TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (router, ZMQ_ROUTER_MANDATORY,                                               &mandatory, sizeof (mandatory)));    int rc = zmq_send (router, "UNKNOWN", 7, ZMQ_SNDMORE);    TEST_ASSERT_EQUAL_INT (-1, rc);    TEST_ASSERT_EQUAL_INT (EHOSTUNREACH, errno);    //  Create dealer called "X" and connect it to our router    void *dealer = test_context_socket (ZMQ_DEALER);    TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (dealer, ZMQ_ROUTING_ID, "X", 1));    TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (dealer, my_endpoint));    //  Get message from dealer to know when connection is ready    send_string_expect_success (dealer, "Hello", 0);    recv_string_expect_success (router, "X", 0);    //  Send a message to connected dealer now    //  It should work    send_string_expect_success (router, "X", ZMQ_SNDMORE);    send_string_expect_success (router, "Hello", 0);    test_context_socket_close (router);    test_context_socket_close (dealer);}
开发者ID:ming-hai,项目名称:libzmq,代码行数:41,


示例4: test_blocking

int test_blocking (int send_hwm_, int msg_cnt_){    // Set up bind socket    void *pub_socket = test_context_socket (ZMQ_PUB);    TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pub_socket, "inproc://a"));    // Set up connect socket    void *sub_socket = test_context_socket (ZMQ_SUB);    TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_socket, "inproc://a"));    //set a hwm on publisher    TEST_ASSERT_SUCCESS_ERRNO (      zmq_setsockopt (pub_socket, ZMQ_SNDHWM, &send_hwm_, sizeof (send_hwm_)));    int wait = 1;    TEST_ASSERT_SUCCESS_ERRNO (      zmq_setsockopt (pub_socket, ZMQ_XPUB_NODROP, &wait, sizeof (wait)));    TEST_ASSERT_SUCCESS_ERRNO (      zmq_setsockopt (sub_socket, ZMQ_SUBSCRIBE, 0, 0));    // Send until we block    int send_count = 0;    int recv_count = 0;    while (send_count < msg_cnt_) {        const int rc = zmq_send (pub_socket, NULL, 0, ZMQ_DONTWAIT);        if (rc == 0) {            ++send_count;        } else if (-1 == rc) {            TEST_ASSERT_EQUAL_INT (EAGAIN, errno);            recv_count += receive (sub_socket);            TEST_ASSERT_EQUAL_INT (send_count, recv_count);        }    }    recv_count += receive (sub_socket);    // Clean up    test_context_socket_close (sub_socket);    test_context_socket_close (pub_socket);    return recv_count;}
开发者ID:dand-oss,项目名称:libzmq,代码行数:41,


示例5: main

int main (void){  void *context = zmq_ctx_new ();  // Socket to send messages on  void *sender = zmq_socket (context, ZMQ_PUSH);  zmq_bind (sender, "tcp://*:5557");  // Socket to send start of batch message on  void *sink = zmq_socket (context, ZMQ_PUSH);  zmq_connect (sink, "tcp://localhost:5558");  printf ("Press Enter when the workers are ready: ");  getchar ();  printf ("Sending tasks to workers…/n");  // The first message is "0" and signals start of batch  s_send (sink, "0");  // Initialize random number generator  srandom ((unsigned) time (NULL));  // Send 100 tasks  int task_nbr;  int total_msec = 0; // Total expected cost in msecs  for (task_nbr = 0; task_nbr < 100; task_nbr++) {    int workload;    // Random workload from 1 to 100msecs    workload = randof (100) + 1;    total_msec += workload;    char string [10];    sprintf (string, "%d", workload);    s_send (sender, string);  }  printf ("Total expected cost: %d msec/n", total_msec);  zmq_close (sink);  zmq_close (sender);  zmq_ctx_destroy (context);  return 0;}
开发者ID:player1537,项目名称:cee-stuff,代码行数:41,


示例6: main

int main(int argc, const char * argv[]) {    char time_buf[TIMESIZE], message[MSGSIZE];    void *ctx = NULL, *publisher = NULL;    int retval = 0, nbytes = 0, lucky_number = 0;    time_t current_time;        ctx = zmq_ctx_new();        publisher = zmq_socket(ctx, ZMQ_PUB);        retval = zmq_bind(publisher, "tcp://*:9000");        if (retval != 0) {        fprintf(stderr, "Unable to bind zmq socket on port 9000/n");        exit(1);    }        srandom(42);    while(1) {        current_time = time(NULL);        ctime_r(&current_time, time_buf);        // Remove the newline added by ctime_r        time_buf[24] = '/0';                lucky_number = (int) (rand() % 1000000L);                sprintf(message, "%s %06d", time_buf, lucky_number);                nbytes = zmq_send(publisher, message, MSGSIZE, 0);        if (nbytes != MSGSIZE) {            fprintf(stderr, "ERROR: Unable to send bytes to subscriber/n");        }                sleep(1);    }        zmq_close(publisher);    zmq_ctx_destroy(ctx);    return 0;}
开发者ID:brefsdal,项目名称:zmqtest,代码行数:41,


示例7: main

int main (){    void *ctx = zmq_init (1);    assert (ctx);        void *pub = zmq_socket (ctx, ZMQ_PUB);    assert (pub);    int rc = zmq_bind (pub, "tcp://*:2211");    assert (rc == 0);        void *sub = zmq_socket (ctx, ZMQ_SUB);    assert (sub);    uint64_t size = 1;    rc = zmq_setsockopt (sub, ZMQ_HWM, &size, sizeof (size));    assert (rc == 0);        int64_t swap = 10000000;    rc = zmq_setsockopt (sub, ZMQ_SWAP, &swap, sizeof (swap));    assert (rc == 0);        rc = zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0);    assert (rc == 0);    rc = zmq_connect (sub, "tcp://127.0.0.1:2211");    assert (rc == 0);    int count;    for (count = 0; count < 100000; count++) {        zmq_msg_t msg;        zmq_msg_init_size (&msg, 0);        zmq_send (pub, &msg, 0);        zmq_msg_close (&msg);    }    int linger = 0;    zmq_setsockopt (pub, ZMQ_LINGER, &linger, sizeof (int));    zmq_setsockopt (sub, ZMQ_LINGER, &linger, sizeof (int));    zmq_close (pub);    zmq_close (sub);    zmq_term (ctx);    return 0;}
开发者ID:amrali,项目名称:issues,代码行数:41,


示例8: test_round_robin_out

void test_round_robin_out (void *ctx){    void *req = zmq_socket (ctx, ZMQ_REQ);    assert (req);    int rc = zmq_bind (req, bind_address);    assert (rc == 0);    const size_t services = 5;    void *rep [services];    for (size_t peer = 0; peer < services; peer++) {        rep [peer] = zmq_socket (ctx, ZMQ_REP);        assert (rep [peer]);        int timeout = 250;        rc = zmq_setsockopt (rep [peer], ZMQ_RCVTIMEO, &timeout, sizeof (int));        assert (rc == 0);        rc = zmq_connect (rep [peer], connect_address);        assert (rc == 0);    }    //  We have to give the connects time to finish otherwise the requests     //  will not properly round-robin. We could alternatively connect the    //  REQ sockets to the REP sockets.    msleep (SETTLE_TIME);        // Send our peer-replies, and expect every REP it used once in order    for (size_t peer = 0; peer < services; peer++) {        s_send_seq (req, "ABC", SEQ_END);        s_recv_seq (rep [peer], "ABC", SEQ_END);        s_send_seq (rep [peer], "DEF", SEQ_END);        s_recv_seq (req, "DEF", SEQ_END);    }    close_zero_linger (req);    for (size_t peer = 0; peer < services; peer++)        close_zero_linger (rep [peer]);    // Wait for disconnects.    msleep (SETTLE_TIME);}
开发者ID:5igm4,项目名称:libzmq,代码行数:41,


示例9: main

intmain(int argc, char *argv[]){	void	*context = NULL;	void	*sender = NULL;	FILE	*fp = NULL;	char	 line[1024];	if (argc <= 1) {		printf("provide a file/n");		return ERROR;	}	if (access(argv[1], F_OK) == -1 ) {		printf("%s file does not exist/n", argv[1]);		return ERROR;	}	fp = fopen(argv[1], "r");	if (fp == NULL) {		printf("unable to open %s/n", argv[1]);		return ERROR;	}	context = zmq_ctx_new();	sender = zmq_socket(context, ZMQ_PUSH);	set_socket_timeout(sender);	zmq_bind(sender, VENTBIND);	while(fgets(line, sizeof(line), fp)) {		if (line[0] == '#')			continue;		if (s_send(sender, line) < 0)			perror("s_send");	}	fclose(fp);	zmq_close(sender);	zmq_ctx_destroy(context);	return OK;}
开发者ID:ricardomaraschini,项目名称:c-old-stuff,代码行数:41,


示例10: zmq_socket

static void *step2 (void *context){    // Bind inproc socket before starting step1    void *receiver = zmq_socket (context, ZMQ_PAIR);    zmq_bind (receiver, "inproc://step2");    pthread_t thread;    pthread_create (&thread, NULL, step1, context);    // Wait for signal and pass it on    char *string = s_recv (receiver);    free (string);    zmq_close (receiver);    // Connect to step3 and tel it we're ready    void *xmitter = zmq_socket (context, ZMQ_PAIR);    zmq_connect (xmitter, "inproc://step3");    s_send (xmitter, "READY");    zmq_close (xmitter);    return NULL;}
开发者ID:4179e1,项目名称:misc,代码行数:21,


示例11: zmq_socket

void Van::bind() {  receiver_ = zmq_socket(context_, ZMQ_ROUTER);  CHECK(receiver_ != nullptr)      << "create receiver socket failed : " << zmq_strerror(errno);  std::string addr = "tcp://*:";  if (FLAGS_bind_to) {    LOG(INFO) << "Use port from command line";    addr += std::to_string(FLAGS_bind_to);  } else {    LOG(INFO) << "Use port from node specification";    CHECK(myNode_.has_port()) << myNode_.ShortDebugString();    addr += std::to_string(myNode_.port());  }  if (FLAGS_local) {    addr = "ipc:///tmp/" + myNode_.id();  }  CHECK(zmq_bind(receiver_, addr.c_str()) == 0)      << "bind to " << addr << " failed:" << zmq_strerror(errno);  VLOG(1) << "Bind to " << addr;}
开发者ID:lacozhang,项目名称:numopt,代码行数:21,


示例12: test_ev_zmq

/* send 100 messages over PAIR sockets * sender in one event handler, receiver in another */void test_ev_zmq (void){    struct ev_loop *loop;    void *zctx;    void *zin, *zout;    int i;    ev_zmq win, wout;    ok ((loop = ev_loop_new (EVFLAG_AUTO)) != NULL,        "ev_loop_new works");    ok ((zctx = zmq_init (1)) != NULL,        "initialized zmq context");    ok ((zout = zmq_socket (zctx, ZMQ_PAIR)) != NULL        && zmq_bind (zout, "inproc://eventloop_test") == 0,        "PAIR socket bind ok");    ok ((zin = zmq_socket (zctx, ZMQ_PAIR)) != NULL        && zmq_connect (zin, "inproc://eventloop_test") == 0,        "PAIR socket connect ok");    i = 0;    ev_zmq_init (&win, zsock_rx_cb, zin, EV_READ);    win.data = &i;    ev_zmq_init (&wout, zsock_tx_cb, zout, EV_WRITE);    ev_zmq_start (loop, &win);    ev_zmq_start (loop, &wout);    ok (ev_run (loop, 0) == 0,        "both watchers removed themselves and ev_run exited");    ev_zmq_stop (loop, &win);    ev_zmq_stop (loop, &wout);    cmp_ok (i, "==", 100,        "ev_zmq handler ran 100 times");    ev_loop_destroy (loop);    zmq_close (zin);    zmq_close (zout);    zmq_ctx_destroy (zctx);}
开发者ID:surajpkn,项目名称:flux-core,代码行数:43,


示例13: main

int main(){    int rc;    void *ctx, *s;    zmq_msg_t query, resultset;    const char *query_string, *resultset_string = "ok";    ctx = zmq_init(1);    assert(ctx);    s = zmq_socket(ctx, ZMQ_REP);    assert(s);    rc = zmq_bind(s, "tcp://127.0.0.1:5555");    assert(rc == 0);    while (1)    {        rc = zmq_msg_init(&query);        assert(rc == 0);        rc = zmq_recv(s, &query, 0);        assert(rc == 0);        query_string = (const char *)zmq_msg_data(&query);        printf("recv: %s/n", query_string);        zmq_msg_close(&query);        rc = zmq_msg_init_size(&resultset, strlen(resultset_string)+1);        assert(rc == 0);                memcpy(zmq_msg_data(&resultset), resultset_string, strlen(resultset_string)+1);        rc = zmq_send(s, &resultset, 0);        assert(rc == 0);        zmq_msg_close(&resultset);    }    return 0;}
开发者ID:squareqwer,项目名称:practice,代码行数:40,


示例14: stop_monitor

int zmq::socket_base_t::monitor (const char *addr_, int events_){    if (unlikely (ctx_terminated)) {        errno = ETERM;        return -1;    }    //  Support deregistering monitoring endpoints as well    if (addr_ == NULL) {        stop_monitor ();        return 0;    }    //  Parse addr_ string.    std::string protocol;    std::string address;    if (parse_uri (addr_, protocol, address) || check_protocol (protocol))        return -1;    //  Event notification only supported over inproc://    if (protocol != "inproc") {        errno = EPROTONOSUPPORT;        return -1;    }    //  Register events to monitor    monitor_events = events_;    monitor_socket = zmq_socket (get_ctx (), ZMQ_PAIR);    if (monitor_socket == NULL)        return -1;    //  Never block context termination on pending event messages    int linger = 0;    int rc = zmq_setsockopt (monitor_socket, ZMQ_LINGER, &linger, sizeof (linger));    if (rc == -1)        stop_monitor (false);    //  Spawn the monitor socket endpoint    rc = zmq_bind (monitor_socket, addr_);    if (rc == -1)         stop_monitor (false);    return rc;}
开发者ID:snowattitudes,项目名称:libzmq,代码行数:40,


示例15: Log_init

int Log_init(bstring access_log, bstring log_spec){    int rc = 0;    LogConfig *config = NULL;    if(LOG_SOCKET == NULL)     {        check(ZMQ_CTX, "No ZMQ context, cannot start access log.");        if(Setting_get_int("disable.access_logging", 0))        {            log_info("Access log is disabled according to disable.access_logging.");        }         else         {            config = LogConfig_create(access_log, log_spec);            check(config, "Failed to configure access logging.");            LOG_SOCKET = zmq_socket(ZMQ_CTX, ZMQ_PUB);            check(LOG_SOCKET != NULL, "Failed to create access log socket");#ifdef ZMQ_LINGER            int opt = 0;            rc = zmq_setsockopt(LOG_SOCKET, ZMQ_LINGER, &opt, sizeof(opt));            check(rc == 0, "Could not set the linger option.");#endif            rc = zmq_bind(LOG_SOCKET, bdata(log_spec));            check(rc == 0, "Failed to bind access_log zeromq socket.");            pthread_create(&LOG_THREAD, NULL, Log_internal_thread, config);        }    }    return 0;error:    LogConfig_destroy(config);    return -1;}
开发者ID:304471720,项目名称:mongrel2,代码行数:40,


示例16: test_bind_before_connect

void test_bind_before_connect (){    void *ctx = zmq_ctx_new ();    assert (ctx);    // Bind first    void *bindSocket = zmq_socket (ctx, ZMQ_PAIR);    assert (bindSocket);    int rc = zmq_bind (bindSocket, "inproc://bbc");    assert (rc == 0);    // Now connect    void *connectSocket = zmq_socket (ctx, ZMQ_PAIR);    assert (connectSocket);    rc = zmq_connect (connectSocket, "inproc://bbc");    assert (rc == 0);    // Queue up some data    rc = zmq_send_const (connectSocket, "foobar", 6, 0);    assert (rc == 6);    // Read pending message    zmq_msg_t msg;    rc = zmq_msg_init (&msg);    assert (rc == 0);    rc = zmq_msg_recv (&msg, bindSocket, 0);    assert (rc == 6);    void *data = zmq_msg_data (&msg);    assert (memcmp ("foobar", data, 6) == 0);    // Cleanup    rc = zmq_close (connectSocket);    assert (rc == 0);    rc = zmq_close (bindSocket);    assert (rc == 0);    rc = zmq_ctx_term (ctx);    assert (rc == 0);}
开发者ID:GameFilebyOpenSourse,项目名称:libzmq,代码行数:40,


示例17: zmq_socket

bool ztop::InitialService(std::vector<std::pair<std::string, std::string>> servicePair, ztop*pztop){	auto lambda_setsocket = [](std::pair<std::string, std::string>& sPair, ztop*pztop){		void*s = zmq_socket(pztop->ctx, ZMQ_PUSH);		int rc = zmq_bind(s, sPair.second.c_str());		if (rc != -1)		{			pztop->pairs.insert(std::make_pair(sPair.first, s));			pztop->vItems.push_back({ s, 0, ZMQ_POLLIN, 0 });/*			pztop->jobSendSoketSets.insert(s);*/			std::cerr << sPair.first << " start success:" << sPair.second << std::endl;		}		else			std::cerr << __FUNCTION__ << ":"<<"service not start,with err:=====>" << zmq_strerror(zmq_errno());	};	for_each(servicePair.begin(), servicePair.end(), [&](std::pair<std::string, std::string>& sPair){		lambda_setsocket(sPair, pztop);	});	return true;}
开发者ID:tesla64k,项目名称:lightdistribute,代码行数:22,


示例18: main

int main (void){    setup_test_environment();    void *ctx = zmq_ctx_new ();    assert (ctx);        //  Spawn ZAP handler    void *zap_thread = zmq_threadstart (&zap_handler, ctx);    //  Server socket will accept connections    void *server = zmq_socket (ctx, ZMQ_DEALER);    assert (server);    int rc = zmq_setsockopt (server, ZMQ_IDENTITY, "IDENT", 6);    assert (rc == 0);    rc = zmq_bind (server, "tcp://*:9999");    assert (rc == 0);            //  Client socket that will try to connect to server    void *client = zmq_socket (ctx, ZMQ_DEALER);    assert (client);    rc = zmq_connect (client, "tcp://localhost:9999");    assert (rc == 0);        bounce (server, client);        rc = zmq_close (client);    assert (rc == 0);    rc = zmq_close (server);    assert (rc == 0);        //  Shutdown    rc = zmq_ctx_term (ctx);    assert (rc == 0);        //  Wait until ZAP handler terminates.    zmq_threadclose (zap_thread);    return 0;}
开发者ID:Magnoliae,项目名称:libzmq,代码行数:39,


示例19: main

int main (void){    void *context = zmq_ctx_new ();    void *responder = zmq_socket (context, ZMQ_REP);    int i=1;    char skeystr[] = "JTKVSB%%)wK0E.X)V>+}o?pNmC{O&4W4b!Ni{Lh6";    uint8_t server_key [32];    zmq_z85_decode (server_key, skeystr);    zmq_setsockopt(responder, ZMQ_CURVE_SERVER, &i, sizeof(i));    zmq_setsockopt(responder, ZMQ_CURVE_SECRETKEY, &server_key, sizeof(server_key));    int rc = zmq_bind (responder, "tcp://*:55555");    assert (rc == 0);    while (1) {        char buffer [10];        zmq_recv (responder, buffer, 10, 0);        printf ("Received Hello/n");        sleep (1);        zmq_send (responder, "World", 5, 0);    }    return 0;}
开发者ID:eselyavka,项目名称:C,代码行数:22,


示例20: main

int main (void){    void *context = zmq_ctx_new ();    void *socket = zmq_socket (context, ZMQ_REP);    zmq_bind (socket, "tcp://*:5555");    s_catch_signals ();    while (true) {        //  Blocking read will exit on a signal        zmq_msg_t message;        zmq_msg_init (&message);        zmq_msg_recv (&message, socket, 0);        if (s_interrupted) {            printf ("W: interrupt received, killing server.../n");            break;        }    }    zmq_close (socket);    zmq_ctx_destroy (context);    return 0;}
开发者ID:343829084,项目名称:zguide,代码行数:22,


示例21: test_leak

void test_leak (void){    char my_endpoint[256];    void *ctx = zmq_ctx_new ();    assert (ctx);    void *sb = zmq_socket (ctx, ZMQ_REP);    assert (sb);    int rc = zmq_bind (sb, "ipc://*");    assert (rc == 0);    size_t len = sizeof(my_endpoint);    rc = zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, my_endpoint, &len);    assert (rc == 0);    void *sc = zmq_socket (ctx, ZMQ_REQ);    assert (sc);    rc = zmq_connect (sc, my_endpoint);    assert (rc == 0);    rc = s_send (sc, "leakymsg");    assert (rc == strlen ("leakymsg"));    char *buf = s_recv (sb);    free (buf);    rc = zmq_close (sc);    assert (rc == 0);    msleep (SETTLE_TIME);    rc = s_send (sb, "leakymsg");    assert (rc == strlen ("leakymsg"));    rc = zmq_close (sb);    assert (rc == 0);    rc = zmq_ctx_term (ctx);    assert (rc == 0);}
开发者ID:AmesianX,项目名称:libzmq,代码行数:39,


示例22: main

int main (void){    setup_test_environment();    void *ctx = zmq_ctx_new ();    assert (ctx);    void *sb = zmq_socket (ctx, ZMQ_REP);    assert (sb);    int rc = zmq_bind (sb, "inproc://a");    assert (rc == 0);    rc = zmq_unbind (sb, "inproc://a");    assert (rc == 0);    rc = zmq_close (sb);    assert (rc == 0);    rc = zmq_ctx_term (ctx);    assert (rc == 0);    return 0;}
开发者ID:5igm4,项目名称:libzmq,代码行数:22,


示例23: main

int main(void){  void *ctx = zmq_ctx_new();  void *sock = zmq_socket(ctx, ZMQ_ROUTER);  int rc = zmq_bind(sock, "tcp://127.0.0.1:5555");  assert(0 == rc);  char buf[128];  int recvBytes = 0;  while (1) {    // recv  id    recvBytes = zmq_recv(sock, buf, sizeof(buf), 0);    if (0 < recvBytes) {      // send it back      printf("recv id bytes=%d/n", recvBytes);      zmq_send(sock, buf, recvBytes, ZMQ_SNDMORE);    }    // delimiter emtpy frame    recvBytes = zmq_recv(sock, buf, sizeof(buf), 0);    assert(0 == recvBytes);    recvBytes = zmq_recv(sock, buf, sizeof(buf), 0);    // actual message    if (0 < recvBytes) {      // send it back      buf[recvBytes] = '/0';      printf("recv msg %s, bytes=%d/n", buf, recvBytes);      zmq_send(sock, "", 0, ZMQ_SNDMORE);      zmq_send(sock, buf, recvBytes, 0);    }  }  zmq_close(sock);  zmq_ctx_destroy(ctx);  return 0;}
开发者ID:oopschen,项目名称:zeromq-learn,代码行数:39,


示例24: main

int main (void) {    setup_test_environment ();    void *ctx = zmq_ctx_new ();    assert (ctx);        void *stream = zmq_socket (ctx, ZMQ_STREAM);    assert (stream);    void *dealer = zmq_socket (ctx, ZMQ_DEALER);    assert (dealer);        int rc = zmq_bind (stream, "tcp://127.0.0.1:5555");    assert (rc >= 0);    rc = zmq_connect (dealer, "tcp://127.0.0.1:5555");    assert (rc >= 0);    zmq_send (dealer, "", 0, 0);        zmq_msg_t ident, empty;    zmq_msg_init (&ident);    rc = zmq_msg_recv (&ident, stream, 0);    assert (rc >= 0);    rc = zmq_msg_init_data (&empty, (void *) "", 0, NULL, NULL);    assert (rc >= 0);        rc = zmq_msg_send (&ident, stream, ZMQ_SNDMORE);    assert (rc >= 0);    rc = zmq_msg_close (&ident);    assert (rc >= 0);        rc = zmq_msg_send (&empty, stream, 0);    assert (rc >= 0);        //  This close used to fail with Bad Address    rc = zmq_msg_close (&empty);    assert (rc >= 0);        close_zero_linger (dealer);    close_zero_linger (stream);    zmq_ctx_term (ctx);}
开发者ID:GameFilebyOpenSourse,项目名称:libzmq,代码行数:39,


示例25: main

int main(){  void *context=zmq_ctx_new();  void *sink=zmq_socket(context, ZMQ_ROUTER);  zmq_bind(sink, "inproc://example");  void *anonymous=zmq_socket(context, ZMQ_REQ);  zmq_connect(anonymous, "inproc://example");  s_send(anonymous, "ROUTER uses a generated UUID", 0, NULL);  s_dump(sink);  void *identified=zmq_socket(context, ZMQ_REQ);  zmq_setsockopt(identified, ZMQ_IDENTITY, "PEER2", 5);  zmq_connect(identified, "inproc://example");  s_send(identified, "ROUTER socker uses REQ's socker identity", 0, NULL);  s_dump(sink);  zmq_close(identified);  zmq_close(anonymous);  zmq_close(sink);  zmq_ctx_destroy(context);  return 0;}
开发者ID:solomonwzs,项目名称:zmq_test,代码行数:22,


示例26: main

int main(void){    // Prepare our context and socket    void *context = zmq_ctx_new();    void *receiver = zmq_socket(context, ZMQ_PULL);    zmq_bind(receiver, "tcp://*:5558");    // Wait for start of batch    char *string = s_recv(receiver);    free(string);    printf("start of batch/n");    // Start our clock now    int64_t start_time = s_clock();    // Process 100 confirmations    int task_nbr;    for(task_nbr=0; task_nbr<100; task_nbr++)    {        char *string = s_recv(receiver);        free(string);        if(task_nbr % 10 == 0)        {            printf(":");        }        else        {            printf(".");        }        fflush(stdout);    }    // Calculate and report duration of batch    printf("/nTotal elapsed time: %d msec/n", (int)(s_clock() - start_time));        zmq_close(receiver);    zmq_ctx_destroy(context);    return 0;}
开发者ID:QingyunLiu,项目名称:my-nodejs-learn,代码行数:39,


示例27: prep_server_socket

static voidprep_server_socket(void * ctx, int set_heartbeats, int is_curve, void ** server_out, void ** mon_out){    int rc;    //  We'll be using this socket in raw mode    void *server = zmq_socket (ctx, ZMQ_ROUTER);    assert (server);    int value = 0;    rc = zmq_setsockopt (server, ZMQ_LINGER, &value, sizeof (value));    assert (rc == 0);    if(set_heartbeats) {        value = 50;        rc = zmq_setsockopt (server, ZMQ_HEARTBEAT_IVL, &value, sizeof(value));        assert (rc == 0);    }    if(is_curve)        setup_curve(server, 1);    rc = zmq_bind (server, "tcp://127.0.0.1:5556");    assert (rc == 0);    //  Create and connect a socket for collecting monitor events on dealer    void *server_mon = zmq_socket (ctx, ZMQ_PAIR);    assert (server_mon);    rc = zmq_socket_monitor (server, "inproc://monitor-dealer",          ZMQ_EVENT_CONNECTED | ZMQ_EVENT_DISCONNECTED | ZMQ_EVENT_ACCEPTED);    assert (rc == 0);    //  Connect to the inproc endpoint so we'll get events    rc = zmq_connect (server_mon, "inproc://monitor-dealer");    assert (rc == 0);    *server_out = server;    *mon_out = server_mon;}
开发者ID:GameFilebyOpenSourse,项目名称:libzmq,代码行数:39,


示例28: main

//  We will do this all in one thread to emphasize the sequence//  of events...int main (void) {    void *context = zmq_init (1);    void *client = zmq_socket (context, ZMQ_ROUTER);    zmq_bind (client, "ipc://routing.ipc");    void *worker = zmq_socket (context, ZMQ_REP);    zmq_setsockopt (worker, ZMQ_IDENTITY, "A", 1);    zmq_connect (worker, "ipc://routing.ipc");    //  Wait for the worker to connect so that when we send a message    //  with routing envelope, it will actually match the worker...    sleep (1);    //  Send papa address, address stack, empty part, and request    s_sendmore (client, "A");    s_sendmore (client, "address 3");    s_sendmore (client, "address 2");    s_sendmore (client, "address 1");    s_sendmore (client, "");    s_send     (client, "This is the workload");    //  Worker should get just the workload	printf("begine dump worker/n");    s_dump (worker);    //  We don't play with envelopes in the worker    s_send (worker, "This is the reply");    //  Now dump what we got off the ROUTER socket...	printf("begine dump client/n");    s_dump (client);    zmq_close (client);    zmq_close (worker);    zmq_term (context);    return 0;}
开发者ID:zhangyuchi,项目名称:cpptestzj,代码行数:41,


示例29: main

int main (void){    int64_t more;    size_t more_size = sizeof(more);    setup_test_environment();    void *ctx = zmq_ctx_new ();    assert (ctx);    void *sb = zmq_socket (ctx, ZMQ_PUB);    assert (sb);    int rc = zmq_bind (sb, "inproc://a");    assert (rc == 0);    void *sc = zmq_socket (ctx, ZMQ_SUB);    assert (sc);    rc = zmq_connect (sc, "inproc://a");    assert (rc == 0);    memset(&more, 0xFF, sizeof(int64_t));    zmq_getsockopt(sc, ZMQ_RCVMORE, &more, &more_size);    assert (more_size == sizeof(int));    assert (more == 0);    // Cleanup    rc = zmq_close (sc);    assert (rc == 0);    rc = zmq_close (sb);    assert (rc == 0);    rc = zmq_ctx_term (ctx);    assert (rc == 0);    return 0 ;}
开发者ID:DarkDare,项目名称:zeromq4-1,代码行数:38,


示例30: main

int main(){	struct ev_loop *loop = ev_default_loop(0);	ev_signal signal_watcher;	ev_signal *p_signal_watcher = &signal_watcher;	ev_signal_init(p_signal_watcher, sigint_cb, SIGINT);	ev_signal_start(loop, &signal_watcher);	void *zctx = zmq_ctx_new();	void *zsock_recv = zmq_socket(zctx, ZMQ_PULL);	assert(zsock_recv!=NULL);	int rc = zmq_bind(zsock_recv, "inproc://channel");	assert(rc!=-1);	ev_zsock_t wz;	ev_zsock_init(&wz, zsock_cb, zsock_recv, EV_READ);	ev_zsock_start(loop, &wz);	void *zsock_send = zmq_socket(zctx, ZMQ_PUSH);	assert(zsock_send!=NULL);	rc = zmq_connect(zsock_send, "inproc://channel");	assert(rc!=-1);	ev_timer timeout_watcher;	ev_timer *p_timeout_watcher = &timeout_watcher;	ev_timer_init (p_timeout_watcher, timeout_cb, 1.0, 1.0);	timeout_watcher.data = zsock_send;	ev_timer_start (loop, &timeout_watcher);	ev_run (loop, 0);	printf("loop exited/n");	zmq_close(zsock_recv);	zmq_close(zsock_send);	zmq_ctx_destroy(zctx);	return 0;}
开发者ID:stanjiang,项目名称:zmq_libev,代码行数:38,



注:本文中的zmq_bind函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ zmq_close函数代码示例
C++ zmq_assert函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。