本文整理汇总了C++中zmq_msg_send函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_msg_send函数的具体用法?C++ zmq_msg_send怎么用?C++ zmq_msg_send使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zmq_msg_send函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: zmq_ctx_new
void *blitScreen(void *) {
void *context = zmq_ctx_new ();
void *requester;
requester = zmq_socket (context, ZMQ_REQ);
zmq_connect(requester, "tcp://mensadisplay:5556");
// zmq_connect(requester, "tcp://192.168.178.147:5570");
// zmq_connect(requester, "tcp://localhost:5556");
while(1) {
zmq_msg_t msg;
zmq_msg_init_size(&msg, sizeof(msgBlit) + WIDTH * HEIGHT);
memcpy(zmq_msg_data(&msg), screen, sizeof(msgBlit) + WIDTH * HEIGHT);
zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
zmq_msg_init_size(&msg, 0);
zmq_msg_send(&msg, requester, 0);
zmq_recv(requester, NULL, 0, 0);
}
zmq_close(requester);
zmq_ctx_destroy(context);
return nullptr;
}
示例2: send_int_array
int send_int_array(const int arr[], size_t count, role *r, const char *label)
{
int rc = 0;
zmq_msg_t msg;
size_t size = sizeof(int) * count;
#ifdef __DEBUG__
fprintf(stderr, " --> %s ", __FUNCTION__);
#endif
if (label != NULL) {
#ifdef __DEBUG__
fprintf(stderr, "{label: %s}", label);
#endif
zmq_msg_t msg_label;
char *buf_label = (char *)calloc(sizeof(char), strlen(label));
memcpy(buf_label, label, strlen(label));
zmq_msg_init_data(&msg_label, buf_label, strlen(label), _dealloc, NULL);
switch (r->type) {
case SESSION_ROLE_P2P:
rc = zmq_msg_send(r->p2p->ptr, &msg_label, ZMQ_SNDMORE);
break;
case SESSION_ROLE_GRP:
rc = zmq_msg_send(r->grp->out->ptr, &msg_label, ZMQ_SNDMORE);
break;
default:
fprintf(stderr, "%s: Unknown endpoint type: %d\n", __FUNCTION__, r->type);
}
zmq_msg_close(&msg_label);
}
int *buf = (int *)malloc(size);
memcpy(buf, arr, size);
zmq_msg_init_data(&msg, buf, size, _dealloc, NULL);
switch (r->type) {
case SESSION_ROLE_P2P:
rc = zmq_msg_send(r->p2p->ptr, &msg, 0);
break;
case SESSION_ROLE_GRP:
#ifdef __DEBUG__
fprintf(stderr, "bcast -> %s(%d endpoints) ", r->grp->name, r->grp->nendpoint);
#endif
rc = zmq_msg_send(r->grp->out->ptr, &msg, 0);
break;
default:
fprintf(stderr, "%s: Unknown endpoint type: %d\n", __FUNCTION__, r->type);
}
zmq_msg_close(&msg);
if (rc != 0) perror(__FUNCTION__);
#ifdef __DEBUG__
fprintf(stderr, ".\n");
#endif
return rc;
}
示例3: main
int main (void) {
void *context = zmq_ctx_new ();
void *requester;
requester = zmq_socket (context, ZMQ_REQ);
zmq_connect(requester, "tcp://mensadisplay:5556");
// zmq_connect(requester, "tcp://192.168.178.147:5570");
// zmq_connect(requester, "tcp://localhost:5556");
msgBlit *snow = reinterpret_cast<msgBlit *>(malloc(sizeof(msgBlit) + WIDTH * HEIGHT));
snow->cmd = CMD_BLIT;
snow->x = 0;
snow->y = 0;
snow->w = WIDTH;
snow->h = HEIGHT;
int on = 0;
while(1) {
zmq_msg_t msg;
zmq_msg_init_size(&msg, sizeof(msgBlit) + WIDTH * HEIGHT);
int d = 0;
switch(on) {
case 0: d = 0; break;
case 1: d = 0; break;
case 2: d = 0; break;
case 3: d = 0; break;
case 4: d = 255; break;
case 5: d = 255; break;
case 6: d = 0; break;
case 7: d = 255; break;
}
for(int i = 0; i < WIDTH * HEIGHT; ++i) {
snow->data[i] = d;
}
on = (on + 1) % 8;
memcpy(zmq_msg_data(&msg), snow, sizeof(msgBlit) + WIDTH * HEIGHT);
zmq_msg_send(&msg, requester, ZMQ_SNDMORE);
zmq_msg_init_size(&msg, 0);
zmq_msg_send(&msg, requester, 0);
zmq_recv(requester, NULL, 0, 0);
}
zmq_close(requester);
zmq_ctx_destroy(context);
return 0;
}
示例4: pub_worker
void* pub_worker(void* arg){
void *ctx = arg;
assert(ctx);
void *qskt = zmq_socket(ctx, ZMQ_REP);
assert(qskt);
int rc = zmq_connect(qskt, "inproc://querys");
assert(rc == 0);
void *pubskt = zmq_socket(ctx, ZMQ_PUB);
assert(pubskt);
rc = zmq_bind(pubskt, "inproc://publish");
assert(rc == 0);
uint8_t cmd;
uint32_t nb;
zmq_msg_t topic_msg, cmd_msg, nb_msg, resp_msg;
zmq_msg_init_data(&topic_msg, topic_str, strlen(topic_str) , NULL, NULL);
fprintf(stdout,"WORKER: ready to receive messages\n");
// NOTE: do NOT reuse this example code, It's broken.
// e.g. topic_msg will be invalid the second time through
while (1){
zmq_msg_send(pubskt, &topic_msg, ZMQ_SNDMORE);
zmq_msg_init(&cmd_msg);
zmq_msg_recv(qskt, &cmd_msg, 0);
memcpy(&cmd, zmq_msg_data(&cmd_msg), sizeof(uint8_t));
zmq_msg_send(pubskt, &cmd_msg, ZMQ_SNDMORE);
zmq_msg_close(&cmd_msg);
fprintf(stdout, "received cmd %u\n", cmd);
zmq_msg_init(&nb_msg);
zmq_msg_recv(qskt, &nb_msg, 0);
memcpy(&nb, zmq_msg_data(&nb_msg), sizeof(uint32_t));
zmq_msg_send(pubskt, &nb_msg, 0);
zmq_msg_close(&nb_msg);
fprintf(stdout, "received nb %u\n", nb);
zmq_msg_init_size(&resp_msg, sizeof(uint8_t));
memset(zmq_msg_data(&resp_msg), 0, sizeof(uint8_t));
zmq_msg_send(qskt, &resp_msg, 0);
zmq_msg_close(&resp_msg);
}
return NULL;
}
示例5: zmq_msg_send
void AsyncJobRouter::forwardToJob(uint64_t apid,
zmq_msg_t* routingFrame,
zmq_msg_t* delimiterFrame,
zmq_msg_t* headerFrame) {
void* outSock = processSocketMap[apid];
zmq_msg_send(routingFrame, outSock, ZMQ_SNDMORE);
zmq_msg_send(delimiterFrame, outSock, ZMQ_SNDMORE);
//Only send MORE flag for the header frame if there are more frames to follow
zmq_msg_send(headerFrame, outSock,
(socketHasMoreFrames(processorInputSocket) ? ZMQ_SNDMORE : 0));
//Proxy the rest of the message (if any)
proxyMultipartMessage(processorInputSocket, outSock);
}
示例6: main
int main(void)
{
void *context = zmq_ctx_new();
void *frontend = zmq_socket(context, ZMQ_ROUTER);
void *backend = zmq_socket(context, ZMQ_DEALER);
zmq_bind(frontend, "tcp://*:5559");
zmq_bind(backend, "tcp://*:5560");
zmq_pollitem_t items[] = {
{frontend, 0, ZMQ_POLLIN, 0},
{backend, 0, ZMQ_POLLIN, 0},
};
while (1) {
zmq_msg_t message;
int more;
zmq_poll(items, 2, -1);
if (items[0].revents & ZMQ_POLLIN) {
while (1) {
zmq_msg_init(&message);
zmq_msg_recv(&message, frontend, 0);
printf("frontend recv: %s\n", (char *)zmq_msg_data(&message));
size_t more_size = sizeof(more);
zmq_getsockopt(frontend, ZMQ_RCVMORE, &more, &more_size);
zmq_msg_send(&message, backend, more ? ZMQ_SNDMORE : 0);
zmq_msg_close(&message);
if (!more)
break;
}
}
if (items[1].revents & ZMQ_POLLIN) {
while (1) {
zmq_msg_init (&message);
zmq_msg_recv(&message, backend, 0);
printf("backend: %s\n", (char *)zmq_msg_data(&message));
size_t more_size = sizeof(more);
zmq_getsockopt(backend, ZMQ_RCVMORE, &more, &more_size);
zmq_msg_send(&message, frontend, more ? ZMQ_SNDMORE : 0);
zmq_msg_close(&message);
if (!more)
break;
}
}
}
zmq_close(frontend);
zmq_close(backend);
zmq_ctx_destroy(context);
return 0;
}
示例7: main
int main (void)
{
// Prepare our context and sockets
void *context = zmq_ctx_new ();
void *frontend = zmq_socket (context, ZMQ_ROUTER);
void *backend = zmq_socket (context, ZMQ_DEALER);
zmq_bind (frontend, "tcp://*:5559");
zmq_bind (backend, "tcp://*:5560");
// Initialize poll set
zmq_pollitem_t items [] = {
{ frontend, 0, ZMQ_POLLIN, 0 },
{ backend, 0, ZMQ_POLLIN, 0 }
};
// Switch messages between sockets
while (1) {
zmq_msg_t message;
zmq_poll (items, 2, -1);
if (items [0].revents & ZMQ_POLLIN) {
while (1) {
// Process all parts of the message
zmq_msg_init (&message);
zmq_msg_recv (&message, frontend, 0);
zmq_msg_send (&message, backend,
zmq_msg_more (&message)? ZMQ_SNDMORE: 0);
zmq_msg_close (&message);
if (!zmq_msg_more (&message))
break; // Last message part
}
}
if (items [1].revents & ZMQ_POLLIN) {
while (1) {
// Process all parts of the message
zmq_msg_init (&message);
zmq_msg_recv (&message, backend, 0);
zmq_msg_send (&message, frontend,
zmq_msg_more (&message)? ZMQ_SNDMORE: 0);
zmq_msg_close (&message);
if (!zmq_msg_more (&message))
break; // Last message part
}
}
}
// We never get here but clean up anyhow
zmq_close (frontend);
zmq_close (backend);
zmq_ctx_destroy (context);
return 0;
}
示例8: main
int main (void)
{
int major, minor, patch;
zmq_version (&major, &minor, &patch);
printf ("Current 0MQ version is %d.%d.%d\n", major, minor, patch);
void *context = zmq_ctx_new ();
// Socket to talk to clients
void *responder = zmq_socket (context, ZMQ_REP);
zmq_bind (responder, "tcp://*:5555");
while (1) {
// Wait for next request from client
char *message = s_recv(responder);
printf ("Received %s\n", message);
// Do some 'work'
sleep (1);
// Send reply back to client
zmq_msg_t reply;
zmq_msg_init_size (&reply, 5);
memcpy (zmq_msg_data (&reply), "World", 5);
zmq_msg_send (&reply, responder, 0);
zmq_msg_close (&reply);
}
// We never get here but if we did, this would be how we end
zmq_close (responder);
zmq_ctx_destroy (context);
return 0;
}
示例9: test_req_message_format
void test_req_message_format (void *ctx)
{
void *req = zmq_socket (ctx, ZMQ_REQ);
assert (req);
void *router = zmq_socket (ctx, ZMQ_ROUTER);
assert (router);
int rc = zmq_bind (req, bind_address);
assert (rc == 0);
size_t len = MAX_SOCKET_STRING;
rc = zmq_getsockopt (req, ZMQ_LAST_ENDPOINT, connect_address, &len);
assert (rc == 0);
rc = zmq_connect (router, connect_address);
assert (rc == 0);
// Send a multi-part request.
s_send_seq (req, "ABC", "DEF", SEQ_END);
zmq_msg_t msg;
zmq_msg_init (&msg);
// Receive peer identity
rc = zmq_msg_recv (&msg, router, 0);
assert (rc != -1);
assert (zmq_msg_size (&msg) > 0);
zmq_msg_t peer_id_msg;
zmq_msg_init (&peer_id_msg);
zmq_msg_copy (&peer_id_msg, &msg);
int more = 0;
size_t more_size = sizeof (more);
rc = zmq_getsockopt (router, ZMQ_RCVMORE, &more, &more_size);
assert (rc == 0);
assert (more);
// Receive the rest.
s_recv_seq (router, 0, "ABC", "DEF", SEQ_END);
// Send back a single-part reply.
rc = zmq_msg_send (&peer_id_msg, router, ZMQ_SNDMORE);
assert (rc != -1);
s_send_seq (router, 0, "GHI", SEQ_END);
// Receive reply.
s_recv_seq (req, "GHI", SEQ_END);
rc = zmq_msg_close (&msg);
assert (rc == 0);
rc = zmq_msg_close (&peer_id_msg);
assert (rc == 0);
close_zero_linger (req);
close_zero_linger (router);
// Wait for disconnects.
msleep (SETTLE_TIME);
}
示例10: reply
void reply()
{
zmq_msg_t reply;
zmq_msg_init_size (&reply, 0);
zmq_msg_send (&reply, zmq_responder, 0);
zmq_msg_close (&reply);
}
示例11: main
int main (void)
{
void *context = zmq_ctx_new ();
// Socket to talk to server
printf ("Connecting to hello world server...\n");
void *requester = zmq_socket (context, ZMQ_REQ);
zmq_connect (requester, "tcp://localhost: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_msg_send (&request, requester, 0);
zmq_msg_close (&request);
zmq_msg_t reply;
zmq_msg_init (&reply);
zmq_msg_recv (&reply, requester, 0);
printf ("Received World %d\n", request_nbr);
zmq_msg_close (&reply);
}
zmq_close (requester);
zmq_ctx_destroy (context);
return 0;
}
示例12: R_zmq_msg_send
SEXP R_zmq_msg_send(SEXP R_rmsg, SEXP R_socket, SEXP R_flags){
int C_rmsg_length = LENGTH(R_rmsg);
int C_ret = -1, C_errno, C_flags = INTEGER(R_flags)[0];
void *C_socket = R_ExternalPtrAddr(R_socket);
zmq_msg_t msg;
if(C_socket != NULL){
C_ret = zmq_msg_init_size(&msg, C_rmsg_length);
if(C_ret == -1){
C_errno = zmq_errno();
REprintf("R_zmq_msg_init_size errno: %d strerror: %s\n",
C_errno, zmq_strerror(C_errno));
}
memcpy(zmq_msg_data(&msg), RAW(R_rmsg), C_rmsg_length);
C_ret = zmq_msg_send(&msg, C_socket, C_flags);
if(C_ret == -1){
C_errno = zmq_errno();
REprintf("R_zmq_msg_send errno: %d strerror: %s\n",
C_errno, zmq_strerror(C_errno));
}
C_ret = zmq_msg_close(&msg);
if(C_ret == -1){
C_errno = zmq_errno();
REprintf("R_zmq_msg_close errno: %d strerror: %s\n",
C_errno, zmq_strerror(C_errno));
}
} else{
REprintf("R_zmq_send: C_socket is not available.\n");
}
return(R_NilValue);
} /* End of R_zmq_msg_send(). */
示例13: main
int main(void) {
void* context = zmq_ctx_new();
// Socket to talk to clients
void* responder = zmq_socket(context, ZMQ_REP);
zmq_bind(responder, "tcp://*:5555");
printf("Starting Hello World server on port 5555\n");
// Run server forever
while(1) {
// Wait for the next request from server
zmq_msg_t request;
zmq_msg_init (&request);
zmq_msg_recv (&request, responder, 0);
printf("Received Hello\n");
zmq_msg_close (&request);
// Do some work
sleep(1);
// Send reply back to client
zmq_msg_t reply;
zmq_msg_init_size(&reply, 6);
memcpy(zmq_msg_data(&reply), "World!", 6);
zmq_msg_send(&reply, responder, 0);
zmq_msg_close(&reply);
}
// We never get here, but clean up for style
zmq_close(responder);
zmq_ctx_destroy(context);
return 0;
}
示例14: main
int main (int argc, char const *argv[]) {
void* context = zmq_ctx_new();
//create a PUB socket
void* publisher = zmq_socket(context, ZMQ_PUB);
int conn = zmq_bind(publisher, "tcp://*:4040");
conn = zmq_bind(publisher, "ipc://stock.ipc");
const char* companies[3] = {"Company1", "Company10", "Company101"};
for(;;) {
int price = count % 17;
int which_company = count % 3;
int index = strlen(companies[which_company]);
char update[64];
sprintf(update, "%s| %d", companies[which_company], price);
zmq_msg_t message;
zmq_msg_init_size(&message, index);
memcpy(zmq_msg_data(&message), update, index);
zmq_msg_send(&message, publisher, 0);
zmq_msg_close(&message);
count++;
}
zmq_close(publisher);
zmq_ctx_destroy(context);
return 0;
}
示例15: main
int main (void)
{
void *context = zmq_ctx_new ();
// Socket to talk to clients
void *responder = zmq_socket (context, ZMQ_REP);
zmq_bind (responder, "tcp://*:5555");
while (1) {
// Wait for next request from client
zmq_msg_t request;
zmq_msg_init (&request);
zmq_msg_recv (&request, responder, 0);
printf ("Received Hello\n");
zmq_msg_close (&request);
// Do some 'work'
sleep (1);
// Send reply back to client
zmq_msg_t reply;
zmq_msg_init_size (&reply, 5);
memcpy (zmq_msg_data (&reply), "World", 5);
zmq_msg_send (&reply, responder, 0);
zmq_msg_close (&reply);
}
// We never get here but if we did, this would be how we end
zmq_close (responder);
zmq_ctx_destroy (context);
return 0;
}