当前位置: 首页>>代码示例>>C++>>正文


C++ zmq_init函数代码示例

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


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

示例1: PROCESS_THREAD

PROCESS_THREAD(test_pub_bind, ev, data) {
    // printf("> test_pub_bind %d, %d, %p\n", process_pt->lc, ev, data);
    // print_event_name(ev);
    // printf("\r\n");
    PROCESS_BEGIN();

    zmq_init();
    zmq_socket_init(&my_sock, ZMQ_PUB);
    // zmq_bind("tcp://*:9999");
    zmq_bind(&my_sock, 9999);

    while(1) {
        if(etimer_expired(&et))
            etimer_set(&et, CLOCK_SECOND);

        PROCESS_WAIT_EVENT();

        if(ev == PROCESS_EVENT_TIMER) {
            printf("Publishing 'Hi there!'\r\n");
            static zmq_msg_t *msg = NULL;
            msg = zmq_msg_from_const_data(0, "Hi there!", 9);
            PT_WAIT_THREAD(process_pt, my_sock.send(&my_sock, msg));
            zmq_msg_destroy(&msg);
        }
    }

    PROCESS_END();
}
开发者ID:Alidron,项目名称:contiki-zeromq,代码行数:28,代码来源:my-zmq-pub.c

示例2: zmq_init

void SampleEscrowServerZmq::StartServer()
{
    std::printf("starting server %s on port %d\n", this->serverName.c_str(), this->serverInfo->port);
    std::cout.flush();

    // Prepare our context and socket
    this->context = zmq_init(1);
    this->serverSocket = zmq_socket(this->context, ZMQ_REP);

    // Configure socket to not wait at close time
    int timeOut = 3000;
#ifdef OT_USE_ZMQ4
    zmq_setsockopt(this->serverSocket, ZMQ_RCVTIMEO, &timeOut, sizeof(timeOut));
    zmq_setsockopt(this->serverSocket, ZMQ_SNDTIMEO, &timeOut, sizeof(timeOut));
#endif
    int linger = 0;
    zmq_setsockopt(this->serverSocket, ZMQ_LINGER, &linger, sizeof (linger));

    std::string connectString = "tcp://";
    connectString += this->serverInfo->url;
    connectString += ":";
    //connectString += btc::to_string(this->serverInfo->port);
    connectString += QString::number(this->serverInfo->port).toStdString();
    zmq_bind(serverSocket, connectString.c_str());
}
开发者ID:plato-cambrian,项目名称:Cambrian-src,代码行数:25,代码来源:sampleescrowserverzmq.cpp

示例3: glbColl_start

/**
 *  glbCollection network service startup
 */
static int 
glbColl_start(struct glbColl *self)
{
    void *context;
    void *frontend;
    void *backend;
    pthread_t storage_outlet;
    int ret;

    ret = pthread_create(&storage_outlet, 
			 NULL, 
			 glbColl_add_storage, (void*)self);

    context = zmq_init(1);

    frontend = zmq_socket(context, ZMQ_PULL);
    backend = zmq_socket(context, ZMQ_PUSH);

    zmq_bind(frontend, "tcp://127.0.0.1:6908");
    zmq_bind(backend, "tcp://127.0.0.1:6909");

    printf("  ++ Collection server is up and running!...\n\n");

    zmq_device(ZMQ_QUEUE, frontend, backend);

    /* we never get here */
    zmq_close(frontend);
    zmq_close(backend);
    zmq_term(context);

    return glb_OK;
}
开发者ID:M0nsteR,项目名称:globbie_storage,代码行数:35,代码来源:glb_collection.c

示例4: main

int main (void)
{
void *context = zmq_init (1);

// Socket to talk to server
printf ("Connecting to test_rep server... \n");
void *requester = zmq_socket (context, ZMQ_REQ);
zmq_connect (requester, "tcp://127.0.0.1:5555");

int request_nbr;
for (request_nbr = 0; request_nbr != 10; request_nbr++) {
zmq_msg_t request;
zmq_msg_init_size (&request, 5);
memcpy (zmq_msg_data (&request), "Hello", 5);
printf ("Sending Hello %d ...\n", request_nbr);
zmq_send (requester, &request, 0);
zmq_msg_close (&request);

zmq_msg_t reply;
zmq_msg_init (&reply);
zmq_recv (requester, &reply, 0);
printf ("Received World %d\n", request_nbr);
zmq_msg_close (&reply);
}
zmq_close (requester);
zmq_term (context);
return 0;
}
开发者ID:ahal,项目名称:moz-zeromq,代码行数:28,代码来源:test_req.c

示例5: hx_zmq_construct

value hx_zmq_construct (value io_threads)
{
	if (!val_is_int(io_threads))
		return alloc_null();
		
	int _io_threads = val_int(io_threads);
	if (_io_threads <= 0) {
		val_throw(alloc_int(EINVAL));
		return alloc_null();
	}
	
	void *c = zmq_init (_io_threads);
	int err = zmq_errno();
	
	if (c == NULL) {
		val_throw (alloc_int(err));
		return alloc_null();
	}
	
	// See: http://nekovm.org/doc/ffi#abstracts_and_kinds
	value v =  alloc_abstract(k_zmq_context_handle,c);
	val_gc(v,finalize_context);		// finalize_context is called when the abstract value is garbage collected
	return v;
	
}
开发者ID:boorik,项目名称:hxzmq,代码行数:25,代码来源:Context.cpp

示例6: main

int main (void) 
{
    s_version_assert (2, 1);
    void *context = zmq_init (1);

    //  Socket to talk to clients
    void *publisher = zmq_socket (context, ZMQ_PUB);
    zmq_bind (publisher, "tcp://*:5561");

    //  Socket to receive signals
    void *syncservice = zmq_socket (context, ZMQ_REP);
    zmq_bind (syncservice, "tcp://*:5562");

    //  Get synchronization from subscribers
    int subscribers = 0;
    while (subscribers < SUBSCRIBERS_EXPECTED) {
        //  - wait for synchronization request
        char *string = s_recv (syncservice);
        free (string);
        //  - send synchronization reply
        s_send (syncservice, "");
        subscribers++;
    }
    //  Now broadcast exactly 1M updates followed by END
    int update_nbr;
    for (update_nbr = 0; update_nbr < 1000000; update_nbr++)
        s_send (publisher, "Rhubarb");

    s_send (publisher, "END");

    zmq_close (publisher);
    zmq_close (syncservice);
    zmq_term (context);
    return 0;
}
开发者ID:Neopallium,项目名称:zguide,代码行数:35,代码来源:syncpub.c

示例7: main

int main (void)
{
    fprintf (stderr, "test_pair_ipc running...\n");

    void *ctx = zmq_init (1);
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_PAIR);
    assert (sb);
    int rc = zmq_bind (sb, "ipc:///tmp/tester");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_PAIR);
    assert (sc);
    rc = zmq_connect (sc, "ipc:///tmp/tester");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_term (ctx);
    assert (rc == 0);

    return 0 ;
}
开发者ID:888,项目名称:zeromq3-x,代码行数:30,代码来源:test_pair_ipc.cpp

示例8: main

int main (void)
{
    fprintf (stderr, "test_reqrep_tipc running...\n");

    void *ctx = zmq_init (1);
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_REP);
    assert (sb);
    int rc = zmq_bind (sb, "tipc://{5560,0,0}");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_REQ);
    assert (sc);
    rc = zmq_connect (sc, "tipc://{5560,0}@0.0.0");
    assert (rc == 0);

    bounce (sb, sc);

    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:cuijw,项目名称:libzmq,代码行数:30,代码来源:test_reqrep_tipc.cpp

示例9: main

int main(int argc, char *argv[])
{
  if (argc < 2) return EXIT_FAILURE;
  int N = atoi(argv[1]);

  printf("N: %d\n", N);

  void *ctx = zmq_init(1);
  void *pub = zmq_socket(ctx, ZMQ_PUB); // Output channel of 0
  assert(pub);
  void *sub = zmq_socket(ctx, ZMQ_SUB); // Input channel of 0
  assert(sub);

  int rc;
  rc = zmq_bind(sub, "tcp://*:8887"); // Waits for publishers
  assert(rc == 0);

  rc = zmq_connect(pub, "tcp://localhost:8888"); // Actively connect to subscribers
  assert(rc == 0);

  zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "", 0);

  int *val = (int *)calloc(N, sizeof(int));
  zmq_msg_t msg;

  long long start_time = sc_time();

  // Send
  int *buf = (int *)calloc(N, sizeof(int));
  memcpy(buf, val, N * sizeof(int));
  zmq_msg_init_data(&msg, buf, N * sizeof(int), _dealloc, NULL);
  zmq_send(pub, &msg, 0);
  zmq_msg_close(&msg);

  // Receive
  zmq_msg_init(&msg);
  zmq_recv(sub, &msg, 0);
  memcpy(val, (int *)zmq_msg_data(&msg), zmq_msg_size(&msg));
  zmq_msg_close(&msg);

  long long end_time = sc_time();

  printf("%s: Time elapsed: %f sec\n", argv[0], sc_time_diff(start_time, end_time));

#ifdef __DEBUG__
  int i;
  printf("%s [ ", argv[0]);
  for (i=0; i<N; ++i) {
    printf("%d ", val[i]);
  }
  printf("]\n");
#endif

  free(val);
  zmq_close(sub);
  zmq_close(pub);
  zmq_term(ctx);

  return EXIT_SUCCESS;
}
开发者ID:D4vidH4mm3r,项目名称:sessc,代码行数:60,代码来源:zmq0.c

示例10: main

//  We will do this all in one thread to emphasize the sequence
//  of events...
int main () {
    void *context = zmq_init (1);

    void *client = zmq_socket (context, ZMQ_XREP);
    zmq_bind (client, "ipc://routing");

    void *worker = zmq_socket (context, ZMQ_REP);
    zmq_setsockopt (worker, ZMQ_IDENTITY, "A", 1);
    zmq_connect (worker, "ipc://routing");

    //  Wait for sockets to stabilize
    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
    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 XREP socket...
    s_dump (client);

    zmq_term (context);
    return 0;
}
开发者ID:dell-esdk,项目名称:zguide,代码行数:35,代码来源:rtpapa.c

示例11: main

int main(){

    void* context = zmq_init(1);

    // socket to receive msgs on: the vent
    void* receiver = zmq_socket(context, ZMQ_PULL);
    zmq_connect( receiver, "tcp://localhost:5557");

    // socket to send msgs to: the sink
    void *sender = zmq_socket( context, ZMQ_PUSH);
    zmq_connect( sender, "tcp://localhost:5558");

    int tasks_received = 0;
    //process
    while(1) {
        char* string = s_recv(receiver);

        fflush(stdout);
        printf("%s.", string);

        //do work
        s_sleep(atoi(string));
        free(string);

        //send results to sink
        s_send(sender, "");
        tasks_received++;
    printf("Task %d got %d tasks\n", getpid(), tasks_received);
    }

    zmq_close(receiver);
    zmq_close(sender);
    zmq_term(0);
    return 0;
}
开发者ID:dgquintas,项目名称:my-code-samples,代码行数:35,代码来源:taskworker.c

示例12: main

int main (int argc, char *argv [])
{
    void *ctx = zmq_init (1);
    assert (ctx);

    void *sb = zmq_socket (ctx, ZMQ_REP);
    assert (sb);
    int rc = zmq_bind (sb, "tcp://127.0.0.1:5555");
    assert (rc == 0);

    void *sc = zmq_socket (ctx, ZMQ_REQ);
    assert (sc);
    rc = zmq_connect (sc, "tcp://127.0.0.1:5555");
    assert (rc == 0);
    
    bounce (sb, sc);

    rc = zmq_close (sc);
    assert (rc == 0);

    rc = zmq_close (sb);
    assert (rc == 0);

    rc = zmq_term (ctx);
    assert (rc == 0);

    return 0 ;
}
开发者ID:scastillo,项目名称:libzmq,代码行数:28,代码来源:test_reqrep_tcp.cpp

示例13: thread

Return<std::string> Zmq::init(const int type) {
  std::stringstream ss;
  ss << port;


  endPoint = address + ":" + ss.str();

  std::cout << "endPoint " << endPoint << std::endl;

  if (Zmq::context == NULL){
    if ((Zmq::context = zmq_init(1)) == NULL) {
      return Return<std::string> (false, 
                                  "Failed to init zmq with 1 thread ("
                                  + std::string(zmq_strerror(zmq_errno())) +")");
    }

  }
  if ((socket = zmq_socket(Zmq::context, type)) == NULL){
    return Return<std::string> (false, 
                                "Failed to to create socket ("
                                + std::string(zmq_strerror(zmq_errno())) +")");
  }
  
  return true;
}
开发者ID:trax44,项目名称:tvirt,代码行数:25,代码来源:Zmq.cpp

示例14: main

int main(){

    void* context = zmq_init(1);
    void* receiver = zmq_socket(context, ZMQ_PULL);

    zmq_bind(receiver, "tcp://*:5558");

    //wait for start of batch
    char *string = s_recv(receiver);
    free(string);

    //start clock
    int64_t start_time = s_clock();

    //process 100
    int tasks_nbr;
    for( tasks_nbr = 0; tasks_nbr < 100; tasks_nbr++){
        char* string = s_recv(receiver);
        if((tasks_nbr / 10)*10 == tasks_nbr){
            printf(":");
        } else{
            printf(".");
        }
        fflush(stdout);
    }

    printf("Total elapsed time: %d msec\n", 
            (int)(s_clock() - start_time));

    zmq_close(receiver);
    zmq_term(context);
    return 0;
}
开发者ID:dgquintas,项目名称:my-code-samples,代码行数:33,代码来源:tasksink.c

示例15: worker_thread

//  Worker using REQ socket to do LRU routing
//
static void *
worker_thread (void *args) {
    void *context = zmq_init (1);
    void *worker = zmq_socket (context, ZMQ_REQ);
    s_set_id (worker);          //  Makes tracing easier
    zmq_connect (worker, "ipc://backend.ipc");

    //  Tell broker we're ready for work
    s_send (worker, "READY");

    while (1) {
        //  Read and save all frames until we get an empty frame
        //  In this example there is only 1 but it could be more
        char *address = s_recv (worker);
        char *empty = s_recv (worker);
        assert (*empty == 0);
        free (empty);

        //  Get request, send reply
        char *request = s_recv (worker);
        printf ("Worker: %s\n", request);
        free (request);

        s_sendmore (worker, address);
        s_sendmore (worker, "");
        s_send     (worker, "OK");
        free (address);
    }
    zmq_close (worker);
    zmq_term (context);
    return NULL;
}
开发者ID:darksuji,项目名称:zguide,代码行数:34,代码来源:lruqueue.c


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