[zeromq-dev] ZMQ_MAX_SOCKETS ignored?

Pieter Hintjens ph at imatix.com
Thu Sep 24 19:17:00 CEST 2015


That is correct, I think.

On Thu, Sep 24, 2015 at 10:17 AM, Auer, Jens <jens.auer at cgi.com> wrote:
> I think I can try to answer my own question. Thinking about it, the option
> probably restricts th number of zeroMQ sockets that can be created in the
> given context, and not the number of TCP sockets that are used in the
> backend. So, when I set the option to 1, I can create 1 zeroMQ socket, e.g.
> a PUB, but have many SUB sockets connected. Is that right?
>
> Cheers,
>   Jens
>
> --
> Jens Auer | CGI | Software-Engineer
> CGI (Germany) GmbH & Co. KG
> Rheinstraße 95 | 64295 Darmstadt | Germany
> T: +49 6151 36860 154
> jens.auer at cgi.com
> Unsere Pflichtangaben gemäß § 35a GmbHG / §§ 161, 125a HGB finden Sie unter
> de.cgi.com/pflichtangaben.
>
> CONFIDENTIALITY NOTICE: Proprietary/Confidential information belonging to
> CGI Group Inc. and its affiliates may be contained in this message. If you
> are not a recipient indicated or intended in this message (or responsible
> for delivery of this message to such person), or you think for any reason
> that this message may have been addressed to you in error, you may not use
> or copy or deliver this message to anyone else. In such case, you should
> destroy this message and are asked to notify the sender by reply e-mail.
> ________________________________
> Von: zeromq-dev-bounces at lists.zeromq.org
> [zeromq-dev-bounces at lists.zeromq.org]" im Auftrag von "Auer, Jens
> [jens.auer at cgi.com]
> Gesendet: Donnerstag, 24. September 2015 09:16
> An: ZeroMQ development list
> Betreff: [zeromq-dev] ZMQ_MAX_SOCKETS ignored?
>
> Hi,
>
> I am trying to use a context with ZMQ_MAX_SOCKETS to restrict the possible
> number of connections. In my example, I set ZMQ_MAX_SOCKETS to 2 and start a
> server with ZMQ_STREAM sockets. The client uses posix sockets to connect to
> the server. From what I see, it seems that the number of sockets is ignored
> because I can connect more than 2 clients. Am I missing something?
>
> The server code:
> #include <zmq.h>
> #include <assert.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> int main()
> {
>     void* ctx = zmq_ctx_new();
>     int rc = zmq_ctx_set( ctx, ZMQ_MAX_SOCKETS, 2 );
>     assert( rc == 0 );
>
>     int major = 0;
>     int minor = 0;
>     int patch = 0;
>
>     zmq_version(&major, &minor, &patch);
>     printf("This is zeroMQ %d.%d.%d\n", major, minor, patch);
>
>     void* s = zmq_socket(ctx, ZMQ_STREAM);
>     assert(s);
>     rc = zmq_bind(s, "tcp://*:10000");
>     assert(rc == 0);
>
>     uint8_t id[256];
>
>     while(1)
>     {
>         printf("Waiting for client...\n");
>         memset(id, 256, '\0');
>         int n = zmq_recv(s, id, 256, 0);
>
>         printf("Client connected\n");
>         for(int i=0; i != n; ++i)
>         {
>             printf("%0x", (int)id[i]);
>         }
>         printf (" (%d)\n", n);
>
>         n = zmq_recv(s, id, 256, 0);
>         assert(n == 0);
>     }
> }
>
> The client code:
> int main()
> {
>     struct sockaddr_in serv_addr;
>     int sockfd;
>     if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
>     {
>         printf("\n Error : Could not create socket \n");
>     }
>
>     memset(&serv_addr, '0', sizeof(serv_addr));
>
>     serv_addr.sin_family = AF_INET;
>     serv_addr.sin_port = htons(10000);
>
>     if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0)
>     {
>         printf("\n inet_pton error occured\n");
>     }
>
>     if( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) <
> 0)
>     {
>        printf("\n Error : Connect Failed \n");
>     }
>
>     int i; std::cin >> i;
>
>     return 0;
> }
>
> Running the server, and stating four clients gives the following output:
> This is zeroMQ 4.1.2
> Waiting for client...
> Client connected
> 06b8b4567 (5)
> Waiting for client...
> Client connected
> 06b8b4568 (5)
> Waiting for client...
> Client connected
> 06b8b4569 (5)
> Waiting for client...
> Client connected
> 06b8b456a (5)
> Waiting for client...
>
> Since I don't see any disconnect messages for the clients, it looks like all
> four clients are connected. netstat confirms this.
>
> Best wishes,
>   Jens
>
> --
> Jens Auer | CGI | Software-Engineer
> CGI (Germany) GmbH & Co. KG
> Rheinstraße 95 | 64295 Darmstadt | Germany
> T: +49 6151 36860 154
> jens.auer at cgi.com
> Unsere Pflichtangaben gemäß § 35a GmbHG / §§ 161, 125a HGB finden Sie unter
> de.cgi.com/pflichtangaben.
>
> CONFIDENTIALITY NOTICE: Proprietary/Confidential information belonging to
> CGI Group Inc. and its affiliates may be contained in this message. If you
> are not a recipient indicated or intended in this message (or responsible
> for delivery of this message to such person), or you think for any reason
> that this message may have been addressed to you in error, you may not use
> or copy or deliver this message to anyone else. In such case, you should
> destroy this message and are asked to notify the sender by reply e-mail.
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>



More information about the zeromq-dev mailing list