1/*
2 Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3
4 This file is part of libzmq, the ZeroMQ core engine in C++.
5
6 libzmq is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 As a special exception, the Contributors give you permission to link
12 this library with independent modules to produce an executable,
13 regardless of the license terms of these independent modules, and to
14 copy and distribute the resulting executable under terms of your choice,
15 provided that you also meet, for each linked independent module, the
16 terms and conditions of the license of that module. An independent
17 module is a module which is not derived from or based on this library.
18 If you modify this library, you must extend this exception to your
19 version of the library.
20
21 libzmq is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24 License for more details.
25
26 You should have received a copy of the GNU Lesser General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
28*/
29
30#include "../include/zmq.h"
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
35// keys are arbitrary but must match local_lat.cpp
36const char server_pubkey[] = "DX4nh=yUn{-9ugra0X3Src4SU-4xTgqxcYY.+<SH";
37const char client_pubkey[] = "<n^oA}I:66W+*ds3tAmi1+KJzv-}k&fC2aA5Bj0K";
38const char client_prvkey[] = "9R9bV}[6z6DC-%$!jTVTKvWc=LEL{4i4gzUe$@Zx";
39
40int main (int argc, char *argv[])
41{
42 const char *connect_to;
43 int message_count;
44 int message_size;
45 void *ctx;
46 void *s;
47 int rc;
48 int i;
49 zmq_msg_t msg;
50 int curve = 0;
51
52 if (argc != 4 && argc != 5) {
53 printf ("usage: remote_thr <connect-to> <message-size> "
54 "<message-count> [<enable_curve>]\n");
55 return 1;
56 }
57 connect_to = argv[1];
58 message_size = atoi (argv[2]);
59 message_count = atoi (argv[3]);
60 if (argc >= 5 && atoi (argv[4])) {
61 curve = 1;
62 }
63
64 ctx = zmq_init (1);
65 if (!ctx) {
66 printf ("error in zmq_init: %s\n", zmq_strerror (errno));
67 return -1;
68 }
69
70 s = zmq_socket (ctx, ZMQ_PUSH);
71 if (!s) {
72 printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
73 return -1;
74 }
75
76 // Add your socket options here.
77 // For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
78 if (curve) {
79 rc = zmq_setsockopt (s, ZMQ_CURVE_SECRETKEY, client_prvkey,
80 sizeof (client_prvkey));
81 if (rc != 0) {
82 printf ("error in zmq_setsockoopt: %s\n", zmq_strerror (errno));
83 return -1;
84 }
85
86 rc = zmq_setsockopt (s, ZMQ_CURVE_PUBLICKEY, client_pubkey,
87 sizeof (client_pubkey));
88 if (rc != 0) {
89 printf ("error in zmq_setsockoopt: %s\n", zmq_strerror (errno));
90 return -1;
91 }
92
93 rc = zmq_setsockopt (s, ZMQ_CURVE_SERVERKEY, server_pubkey,
94 sizeof (server_pubkey));
95 if (rc != 0) {
96 printf ("error in zmq_setsockoopt: %s\n", zmq_strerror (errno));
97 return -1;
98 }
99 }
100
101 rc = zmq_connect (s, connect_to);
102 if (rc != 0) {
103 printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
104 return -1;
105 }
106
107 for (i = 0; i != message_count; i++) {
108 rc = zmq_msg_init_size (&msg, message_size);
109 if (rc != 0) {
110 printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
111 return -1;
112 }
113 rc = zmq_sendmsg (s, &msg, 0);
114 if (rc < 0) {
115 printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
116 return -1;
117 }
118 rc = zmq_msg_close (&msg);
119 if (rc != 0) {
120 printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
121 return -1;
122 }
123 }
124
125 rc = zmq_close (s);
126 if (rc != 0) {
127 printf ("error in zmq_close: %s\n", zmq_strerror (errno));
128 return -1;
129 }
130
131 rc = zmq_ctx_term (ctx);
132 if (rc != 0) {
133 printf ("error in zmq_ctx_term: %s\n", zmq_strerror (errno));
134 return -1;
135 }
136
137 return 0;
138}
139