[zeromq-dev] Limit of characters for zmq_send ?
Bachmair Florian - flexSolution GmbH
Florian.Bachmair at flexsolution.eu
Wed Mar 18 07:22:37 CET 2015
Here is my example: I did it with CURVE but it's the same without CURVE
I publish a String with 1024 'x' ending with "\nENDE" to determine that the end is sent as well
publisher:
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <czmq.h>
#include <assert.h>
// Convert C string to 0MQ string and send to socket
static int s_send(void *socket, char *string) {
int size = zmq_send(socket, string, strlen(string), 0);
return size;
}
// Sends string as 0MQ string, as multipart non-terminal
static int s_sendmore(void *socket, char *string) {
int size = zmq_send(socket, string, strlen(string), ZMQ_SNDMORE);
return size;
}
int main() {
char str[1024];
int i;
strcpy(str, "x");
for (i = 0; i < sizeof(str); i++) {
strcat(str, "x");
}
strcat(str, "\nENDE");
puts(str);
puts("Init Publisher");
const char *addr = "tcp://127.0.0.1:8888";
zctx_t *context = zctx_new();
void *pub = zsocket_new(context, ZMQ_PUB);
zcert_t *server_cert = zcert_load("server_cert.txt_secret");
assert(server_cert);
int rc = zsocket_bind(pub, addr);
assert(rc != -1);
sleep(5);
puts("publish");
for (i = 0; i < 10; i++) {
sleep(1);
s_sendmore(pub, "A");
s_send(pub, str);
}
return 0;
}
subscriber
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <czmq.h>
#include <assert.h>
static char *
s_recv(void *socket) {
char buffer[256];
int size = zmq_recv(socket, buffer, 255, 0);
if (size == -1)
return NULL;
if (size > 255)
size = 255;
buffer[size] = 0;
return strdup(buffer);
}
int main(void) {
puts("Init Subscriber");
fflush(stdout);
zctx_t* context = zctx_new();
void* subscriber = zsocket_new(context, ZMQ_SUB);
zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "A", strlen("A"));
zsocket_connect(subscriber, "tcp://127.0.0.1:8888");
//zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "B", 1);
while (1) {
char *topic = s_recv(subscriber);
char *value = s_recv(subscriber);
printf("%s:%s\n", topic, value);
free(topic);
free(value);
}
// We never get here, but clean up anyhow
zmq_close(subscriber);
zmq_ctx_destroy(context);
}
-----Ursprüngliche Nachricht-----
Von: zeromq-dev-bounces at lists.zeromq.org [mailto:zeromq-dev-bounces at lists.zeromq.org] Im Auftrag von Pieter Hintjens
Gesendet: Dienstag, 17. März 2015 15:23
An: ZeroMQ development list
Betreff: Re: [zeromq-dev] Limit of characters for zmq_send ?
There's no limit. Can you provide a minimal example that shows the problem?
On Tue, Mar 17, 2015 at 12:53 PM, Bachmair Florian - flexSolution GmbH
<Florian.Bachmair at flexsolution.eu> wrote:
> Hi!
>
>
>
> I have tried to send/publish string with 1000 characters. But the subscriber
> only gets about 200-300 of these characters, the rest is cut off.
>
>
>
> Is there a Limit?
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: publisher.c
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150318/4b046f13/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: subscriber.c
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20150318/4b046f13/attachment-0001.c>
More information about the zeromq-dev
mailing list