• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ s_recv函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: worker_task

static void *
worker_task (void *args)
{
    void *context = zmq_ctx_new ();
    void *worker = zmq_socket (context, ZMQ_REQ);
    s_set_id (worker);          //  Set a printable identity
    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 *identity = 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, identity);
        s_sendmore (worker, "");
        s_send     (worker, "OK");
        free (identity);
    }
    zmq_close (worker);
    zmq_ctx_destroy (context);
    return NULL;
}
开发者ID:Alexis-D,项目名称:zguide,代码行数:33,代码来源:lbbroker.c


示例3: worker_thread

//  Worker using REQ socket to do LRU routing
//
static void *
worker_thread (void *arg) {
	zmq::context_t context(1);
    zmq::socket_t worker (context, ZMQ_REQ);
    s_set_id (worker);          //  Makes tracing easier
    worker.connect("ipc://backend.ipc");

    //  Tell backend 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
        std::string address = s_recv (worker);
        {
            std::string empty = s_recv (worker);
            assert (empty.size() == 0);
        }

        //  Get request, send reply
        std::string request = s_recv (worker);
        std::cout << "Worker: " << request << std::endl;

        s_sendmore (worker, address);
        s_sendmore (worker, "");
        s_send     (worker, "OK");
    }
    return (NULL);
}
开发者ID:Lothiraldan,项目名称:zguide,代码行数:31,代码来源:lruqueue.cpp


示例4: main

int main(int argc, char* argv[]) {

  zmq::context_t context(1);

  zmq::socket_t subscriber(context, ZMQ_SUB);
  subscriber.connect("tcp://localhost:5561");
  subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);

  zmq::socket_t syncclient(context, ZMQ_REQ);
  syncclient.connect("tcp://localhost:5562");

  s_send(syncclient, "");

  s_recv(syncclient);
  std::cout << "Connected to subscriber" << std::endl;
  
  int update_nbr = 0;
  while(1) {
    if (s_recv(subscriber).compare("END") == 0) {
      std::cout << "FINE" << std::endl;
      break;
    }

    update_nbr++;
  }

  std::cout << "Received " << update_nbr << "updates" << std::endl;

  return 0;
}
开发者ID:matteosan1,项目名称:zeromq,代码行数:30,代码来源:sync_subscriber.cpp


示例5: 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


示例6: str_recv_from

void str_recv_from (void *s_, char **ptr_content_, char **ptr_address_)
{
    *ptr_address_ = s_recv (s_);
    assert (ptr_address_);

    *ptr_content_ = s_recv (s_);
    assert (ptr_content_);
}
开发者ID:AmesianX,项目名称:libzmq,代码行数:8,代码来源:test_dgram.cpp


示例7: main

int
main (void)
{
	void *context;
	void *subscriber1;
	void *subscriber2;
	char *filter;
	int i;
	int ok;

	context = zmq_ctx_new ();
	subscriber1 = zmq_socket (context, ZMQ_SUB);
	printf ("connecting...\n");
	ok = zmq_connect (subscriber1, "tcp://localhost:5000");
	assert (ok == 0);

	subscriber2 = zmq_socket (context, ZMQ_SUB);
	ok = zmq_connect (subscriber2, "tcp://localhost:5001");
	assert (ok == 0);
	printf ("connected.\n");

	printf ("set filters...\n");
	filter = "filter1";
	ok = zmq_setsockopt (subscriber1,
			     ZMQ_SUBSCRIBE,
			     filter,
			     strlen (filter));
	assert (ok == 0);

	filter = "filter2";
	ok = zmq_setsockopt (subscriber2,
			     ZMQ_SUBSCRIBE,
			     filter,
			     strlen (filter));
	assert (ok == 0);
	printf ("filters set.\n");

	printf ("receiving messages...\n");
	for (i = 0; i < 3; i++)
	{
		char *msg = s_recv (subscriber1);
		printf ("%s\n", msg);
		free (msg);
	}

	for (i = 0; i < 3; i++)
	{
		char *msg = s_recv (subscriber2);
		printf ("%s\n", msg);
		free (msg);
	}

	zmq_close (subscriber1);
	zmq_close (subscriber2);
	zmq_ctx_destroy (context);
	return 0;
}
开发者ID:UCL-CATL,项目名称:cosy-zeromq-matlab,代码行数:57,代码来源:test_subscriber.c


示例8: main

int main(int argc, char *argv[])
{
    void *ctx, *handler, *thread, *server, *client;
    const char *domain, *connect_addr;
    int optval;

    domain = argc > 1 ? argv[1] : "test";
    connect_addr = strcmp(domain, "fail") ? "tcp://127.0.0.1:9000" : "tcp://127.0.0.1:9001";

    assert((ctx = zmq_ctx_new()));

    /* Start ZAP handler thread. */
    assert((handler = zmq_socket(ctx, ZMQ_REP)));
    assert(!(zmq_bind(handler, "inproc://zeromq.zap.01")));
    assert((thread = zmq_threadstart(zap_handler, handler)));

    /* Bind server. */
    assert((server = zmq_socket(ctx, ZMQ_DEALER)));
    assert(!(zmq_setsockopt(server, ZMQ_ZAP_DOMAIN, domain, strlen(domain))));
    assert(!zmq_bind(server, "tcp://127.0.0.1:9000"));

    /* Connect client. */
    assert((client = zmq_socket(ctx, ZMQ_DEALER)));
    optval = 200;
    assert(!(zmq_setsockopt(client, ZMQ_RECONNECT_IVL, &optval, sizeof(optval))));
    optval = 5000;
    assert(!(zmq_setsockopt(client, ZMQ_RECONNECT_IVL_MAX, &optval, sizeof(optval))));
    optval = 30000;
    assert(!(zmq_setsockopt(client, ZMQ_SNDTIMEO, &optval, sizeof(optval))));
    optval = 1;
    assert(!(zmq_setsockopt(client, ZMQ_IMMEDIATE, &optval, sizeof(optval))));
    assert(!zmq_connect(client, connect_addr));

    /* Bounce test. */
    s_send(client, "Hello, Server!");
    assert(!strcmp(s_recv(server), "Hello, Server!"));
    s_send(server, "Hello, Client!");
    assert(!strcmp(s_recv(client), "Hello, Client!"));

    /* Cleanup. */
    assert(!zmq_disconnect(client, connect_addr));
    assert(!zmq_close(client));

    assert(!zmq_unbind(server, "tcp://127.0.0.1:9000"));
    assert(!zmq_close(server));

    assert(!zmq_term(ctx));
    zmq_threadclose(thread);

    return 0;
}
开发者ID:hashstat,项目名称:zeromq-issues,代码行数:51,代码来源:issue.c


示例9: RMessage

// pubRequest by one of the Satellites, this Server just forwards it by publishing it
bool ReefServer::pubRequest(RMessage& msg){
	msg = RMessage();
	bool retBool;
	std::string tagsStr = s_recv(rep); //receive message tags
	std::string bodyStr = s_recv(rep); //receive messagebody
	CJsonArray tagsArray = jsonToArray(tagsStr); //parse Tags
	tagsInitMessage(msg, tagsArray); //initiate msg with the tags
	tagsArray.Clear();

	retBool = checkInterestAndProcess(msg, bodyStr);
	s_sendmore(publisher, ""); //send empty envelope
	s_sendmore(publisher, tagsStr);	//receive tag-part of message and publish it
	s_send(publisher, bodyStr); //receive body-part of message and publish it
	return retBool;
}
开发者ID:iinestorii,项目名称:DigitalReef,代码行数:16,代码来源:ReefServer.cpp


示例10: main

int main(void)
{
    //Create ZMQ Socket
    void *context = zmq_ctx_new();
    
    //Socket to receive messages
    void *receiver = zmq_socket(context, ZMQ_PULL);
    zmq_bind(receiver, "tcp://*:5558");
    
    //Socket to control workers
    void *controller = zmq_socket(context, ZMQ_PUB);
    zmq_bind(controller, "tcp://*:5559");
    
    //Waiting for start 
    char *string = s_recv(receiver);
    free(string);
    
    //Start clock
    int64_t start_time = s_clock();
    
    //Process messages
    int task_nbr;
    for(task_nbr = 0; task_nbr < 100; task_nbr++)
    {
        char *string = s_recv(receiver);
        free(string);
        if((task_nbr / 10) * 10 == task_nbr)
        {
            printf(":");
        }
        else
        {
            printf(".");
        }
        fflush(stdout);
    }
    
    printf("Total elapsed time: %d msec\n", (int)(s_clock()-start_time));
    
    //Send Kille signal
    s_send(controller, "KILL");
    
    zmq_close(receiver);
    zmq_close(controller);
    zmq_ctx_destroy(context);
    
    return 0;
}
开发者ID:HellBlazzar,项目名称:Learning,代码行数:48,代码来源:ParallelTaskSink_KillSignal.c


示例11: worker_thread

static void *
worker_thread (void *arg) {

    zmq::context_t * context = (zmq::context_t *)arg;
    zmq::socket_t worker (*context, ZMQ_REQ);
    
    //  We use a string identity for ease here
    s_set_id (worker);
    worker.connect("ipc://routing.ipc");

    int total = 0;
    while (1) {
        //  Tell the router we're ready for work
        s_send (worker, "ready");

        //  Get workload from router, until finished
        std::string workload = s_recv (worker);
        int finished = (workload.compare("END") == 0);
        
        if (finished) {
            std::cout << "Processed: " << total << " tasks" << std::endl;
            break;
        }
        total++;

        //  Do some random work
        s_sleep(within (100) + 1);
    }
    return (NULL);
}
开发者ID:Lothiraldan,项目名称:zguide,代码行数:30,代码来源:rtmama.cpp


示例12: main

int main (int argc, char *argv [])
{
  // Socket to talk to server
  printf ("Collecting updates from weather server…\n");
  void *context = zmq_ctx_new ();
  void *subscriber = zmq_socket (context, ZMQ_SUB);
  int rc = zmq_connect (subscriber, "tcp://localhost:5556");
  assert (rc == 0);

  // Subscribe to zipcode, default is NYC, 10001
  char *filter = (argc > 1)? argv [1]: "10001 ";
  rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE,
		       filter, strlen (filter));
  assert (rc == 0);

  // Process 100 updates
  int update_nbr;
  long total_temp = 0;
  for (update_nbr = 0; update_nbr < 100; update_nbr++) {
    char *string = s_recv (subscriber);

    int zipcode, temperature, relhumidity;
    sscanf (string, "%d %d %d",
	    &zipcode, &temperature, &relhumidity);
    total_temp += temperature;
    free (string);
  }
  printf ("Average temperature for zipcode '%s' was %dF\n",
	  filter, (int) (total_temp / update_nbr));

  zmq_close (subscriber);
  zmq_ctx_destroy (context);
  return 0;
}
开发者ID:player1537,项目名称:cee-stuff,代码行数:34,代码来源:weather-client.c


示例13: test_plain_vanilla_socket

void test_plain_vanilla_socket ()
{
    // Unauthenticated messages from a vanilla socket shouldn't be received
    struct sockaddr_in ip4addr;
    fd_t s;

    unsigned short int port;
    int rc = sscanf (my_endpoint, "tcp://127.0.0.1:%hu", &port);
    TEST_ASSERT_EQUAL_INT (1, rc);

    ip4addr.sin_family = AF_INET;
    ip4addr.sin_port = htons (port);
#if defined(ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
    ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
#else
    inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr);
#endif

    s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
    rc = connect (s, (struct sockaddr *) &ip4addr, sizeof (ip4addr));
    TEST_ASSERT_GREATER_THAN_INT (-1, rc);
    // send anonymous ZMTP/1.0 greeting
    send (s, "\x01\x00", 2, 0);
    // send sneaky message that shouldn't be received
    send (s, "\x08\x00sneaky\0", 9, 0);
    int timeout = 250;
    zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
    char *buf = s_recv (server);
    if (buf != NULL) {
        printf ("Received unauthenticated message: %s\n", buf);
        TEST_ASSERT_NULL (buf);
    }
    close (s);
}
开发者ID:somdoron,项目名称:libzmq,代码行数:34,代码来源:test_security_plain.cpp


示例14: main

int main(void)
{
    void *context = zmq_ctx_new();
    void *socket = zmq_socket(context, ZMQ_REP);
    zmq_bind(socket, "tcp://*:5555");

    s_catch_signals();
#if 1
    while (1) {
        // Blocking read will exit on a signal
        char buffer[255];
        zmq_recv(socket, buffer, 255, 0);
        if (s_interrupted) {
            printf("W: interrupt received, killing server...\n");
            break;
        }
    }
#else
    while (!s_interrupted) {
        char *message = s_recv(socket);
        if (!message) {
            break;
        }
    }
#endif

    zmq_close(socket);
    zmq_ctx_destroy(context);

#ifdef _MSC_VER
    system("pause");
#endif
    return 0;
}
开发者ID:a524631266,项目名称:Ongoing-Study,代码行数:34,代码来源:interrupt.c


示例15: replay

void replay(void *arg) {
	void *slave = zmq_socket(arg, ZMQ_REQ);
	/*
	if (done % 2) {
		zmq_connect (slave, "tcp://localhost:5562");
	}
	else {
		zmq_connect (slave, "tcp://localhost:5563");
	}*/
	zmq_connect (slave, "tcp://localhost:5562");

	char *string;
	char buf[1024];
	sprintf(buf, "%d", rand());
	s_send(slave, buf);
	string = s_recv(slave);
	if (strcmp(string , buf) != 0) {
		debug_puts("ERROR");
	}
	free(string);
    pthread_mutex_lock(&lock);
    done++;
    pthread_mutex_unlock(&lock);
	zmq_close(slave);
}
开发者ID:prtitrz,项目名称:Thrall,代码行数:25,代码来源:test.c


示例16: main

int main (void) 
{
    void *context = zmq_ctx_new ();

    //  Socket to talk to clients
    void *responder = zmq_socket (context, ZMQ_REP);
    zmq_connect (responder, "tcp://localhost:5560");

    while (true) {
        //  Wait for next request from client
        char *string = s_recv (responder);
        printf ("Received request: [%s]\n", string);
        free (string);

        //  Do some 'work'
        sleep (1);

        //  Send reply back to client
        s_send (responder, "World");
    }
    //  We never get here but clean up anyhow
    zmq_close (responder);
    zmq_ctx_destroy (context);
    return 0;
}
开发者ID:343829084,项目名称:zguide,代码行数:25,代码来源:rrworker.c


示例17: main

int main ()
{
    srand ((unsigned) time (NULL));

    zmq::context_t context(1);
    zmq::socket_t server(context, ZMQ_REP);
    server.bind("tcp://*:5555");

    int cycles = 0;
    while (1) {
        std::string request = s_recv (server);
        cycles++;

        // Simulate various problems, after a few cycles
        if (cycles > 3 && within (3) == 0) {
            std::cout << "I: simulating a crash" << std::endl;
            break;
        }
        else
        if (cycles > 3 && within (3) == 0) {
            std::cout << "I: simulating CPU overload" << std::endl;
            s_sleep (2000);
        }
        std::cout << "I: normal request (" << request << ")" << std::endl;
        s_sleep (1000); // Do some heavy work
        s_send (server, request);
    }
    return 0;
}
开发者ID:tarasko,项目名称:zmq.build,代码行数:29,代码来源:lpserver.cpp


示例18: main

int main () {
    zmq::context_t context(1);

    //  Subscriber tells us when it's ready here
    zmq::socket_t sync(context, ZMQ_PULL);
    sync.bind("tcp://*:5564");

    //  We send updates via this socket
    zmq::socket_t publisher (context, ZMQ_PUB);
    publisher.bind("tcp://*:5565");

    //  Wait for synchronization request
    s_recv (sync);

    //  Now broadcast exactly 10 updates with pause
    int update_nbr;
    for (update_nbr = 0; update_nbr < 10; update_nbr++) {
       
        std::ostringstream oss;
        oss << "Update "<< update_nbr ;
        s_send (publisher, oss.str());
        sleep (1);
    }
    s_send (publisher, "END");

    sleep (1);              //  Give 0MQ/2.0.x time to flush output
    return 0;
}
开发者ID:Alex-Benveniste,项目名称:zguide,代码行数:28,代码来源:durapub.cpp


示例19: main

int main()
{
	// Socket to receive messages on
	void *context = zmq_ctx_new();
	void *receiver = zmq_socket(context, ZMQ_PULL);
	zmq_connect(receiver, "tcp://localhost:5557");

	// Socket to send messages to
	void *sender = zmq_socket(context, ZMQ_PUSH);
	zmq_connect(sender, "tcp://localhost:5558");

	// Process tasks forever
	while (1)
	{
		char *string = s_recv(receiver);
		printf("%s.", string);  // Show progress
		fflush(stdout);
		s_sleep(atoi(string));  // Do the work
		free(string);
		s_send(sender, "");     // Send results to sink
	}

	zmq_close(receiver);
	zmq_close(sender);
	zmq_ctx_destroy(context);
	return 0;
}
开发者ID:kasicass,项目名称:kasicass,代码行数:27,代码来源:taskwork.cpp


示例20: main

int main()
{
	void *context = zmq_ctx_new();
	if (NULL == context)
	{
		printf("aaa\n");
	}
	void *sender = zmq_socket(context, ZMQ_PULL);
	if (NULL == sender)
	{
		printf("aaa\n");
	}

	unsigned int i;
	char url[256];
	sprintf(url, "tcp://127.0.0.1:5557");
	zmq_connect(sender, url);
	for(i=0; ; i++)
	{
		char *temp = s_recv(sender);
		if (strcmp(temp, "exit") == 0)
			break;
		//printf("buff: %s", temp);
	}
	zmq_close(sender);
	zmq_ctx_destroy(context);
}
开发者ID:FMX,项目名称:IPC-performance-compare,代码行数:27,代码来源:pull.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ s_rnge函数代码示例发布时间:2022-05-30
下一篇:
C++ s_new函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap