Broadcasting to subnet address using pyzmq












0















I am trying to use broadcasting packets to subnet address, I successfully tried to do that using socket's broadcast option, But I recently started learning ZeroMQ so I would like to use it to broadcast the packets to the subnet. I used zmq.PUB, zmq.SUB but at the subscriber side, the packets are undelivered because I use subnet address. If I use IP address of the machine then it works, but that's not what I want.



Is there any option for broadcasting using ZMQ?





Here is the code I tried so far:



Publisher:



import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://192.X.X.255:9999") # Note.

while True:
socket.send_string('hello')
time.sleep(1)




Subscriber:



context = zmq.Context()
sub=context.socket(zmq.SUB) # Note.
sub.setsockopt(zmq.SUBSCRIBE, b"") # Note.
sub.connect('tcp://192.x.x.255:9999') -> publishing only to subnet

while True:
print(sub.recv())




We can do the broadcasting of packets using a regular socket, for example, using:



sock.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)


But I want to replace this in a way I do it with ZMQ. Does the ZMQ really have a broadcast discovery in a different way or we should use the same code above as we do for regular broadcasting?










share|improve this question

























  • I don't know about "subnet address" meaning, but with using the .bind("tcp://*:1234") in publisher side, each subscriber could connect on it and get the message over ZMQ with .connect("tcp://publisher-ip:1234"), Isn't that what you are looking for?

    – Benyamin Jafari
    Nov 24 '18 at 20:29











  • Hi, Subnet address is the ip address and the broadcast address mix, for example only the ppl connect to the router wifi gets the message which we send. The address will look like 192.167.1.255, You can see in your ifconfig. So this will avoid sending message to all.(255.255.255.255) @Benyamin jafari . My publisher and subscriber both will use same subnet address. One to publish and other one to subscriber.

    – keerthana
    Nov 24 '18 at 20:32













  • Hi, I think still do not understand what you mean. So I will take an example as an answer, if it wouldn't help you, I'll remove it.

    – Benyamin Jafari
    Nov 24 '18 at 20:43











  • @BenyaminJafari The answer you posted might help only for the publisher who wants to publish to the whole network. "*" this means i think 255.255.255.255 address. Everyone can listen to the publisher, I want it to be private thats why i use subnet address. By the way if you could help, Apart from pub-sub or whatever messaging pattern, i really need to find a zmq way for broadcasting udp packet.

    – keerthana
    Nov 24 '18 at 20:49
















0















I am trying to use broadcasting packets to subnet address, I successfully tried to do that using socket's broadcast option, But I recently started learning ZeroMQ so I would like to use it to broadcast the packets to the subnet. I used zmq.PUB, zmq.SUB but at the subscriber side, the packets are undelivered because I use subnet address. If I use IP address of the machine then it works, but that's not what I want.



Is there any option for broadcasting using ZMQ?





Here is the code I tried so far:



Publisher:



import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://192.X.X.255:9999") # Note.

while True:
socket.send_string('hello')
time.sleep(1)




Subscriber:



context = zmq.Context()
sub=context.socket(zmq.SUB) # Note.
sub.setsockopt(zmq.SUBSCRIBE, b"") # Note.
sub.connect('tcp://192.x.x.255:9999') -> publishing only to subnet

while True:
print(sub.recv())




We can do the broadcasting of packets using a regular socket, for example, using:



sock.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)


But I want to replace this in a way I do it with ZMQ. Does the ZMQ really have a broadcast discovery in a different way or we should use the same code above as we do for regular broadcasting?










share|improve this question

























  • I don't know about "subnet address" meaning, but with using the .bind("tcp://*:1234") in publisher side, each subscriber could connect on it and get the message over ZMQ with .connect("tcp://publisher-ip:1234"), Isn't that what you are looking for?

    – Benyamin Jafari
    Nov 24 '18 at 20:29











  • Hi, Subnet address is the ip address and the broadcast address mix, for example only the ppl connect to the router wifi gets the message which we send. The address will look like 192.167.1.255, You can see in your ifconfig. So this will avoid sending message to all.(255.255.255.255) @Benyamin jafari . My publisher and subscriber both will use same subnet address. One to publish and other one to subscriber.

    – keerthana
    Nov 24 '18 at 20:32













  • Hi, I think still do not understand what you mean. So I will take an example as an answer, if it wouldn't help you, I'll remove it.

    – Benyamin Jafari
    Nov 24 '18 at 20:43











  • @BenyaminJafari The answer you posted might help only for the publisher who wants to publish to the whole network. "*" this means i think 255.255.255.255 address. Everyone can listen to the publisher, I want it to be private thats why i use subnet address. By the way if you could help, Apart from pub-sub or whatever messaging pattern, i really need to find a zmq way for broadcasting udp packet.

    – keerthana
    Nov 24 '18 at 20:49














0












0








0


0






I am trying to use broadcasting packets to subnet address, I successfully tried to do that using socket's broadcast option, But I recently started learning ZeroMQ so I would like to use it to broadcast the packets to the subnet. I used zmq.PUB, zmq.SUB but at the subscriber side, the packets are undelivered because I use subnet address. If I use IP address of the machine then it works, but that's not what I want.



Is there any option for broadcasting using ZMQ?





Here is the code I tried so far:



Publisher:



import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://192.X.X.255:9999") # Note.

while True:
socket.send_string('hello')
time.sleep(1)




Subscriber:



context = zmq.Context()
sub=context.socket(zmq.SUB) # Note.
sub.setsockopt(zmq.SUBSCRIBE, b"") # Note.
sub.connect('tcp://192.x.x.255:9999') -> publishing only to subnet

while True:
print(sub.recv())




We can do the broadcasting of packets using a regular socket, for example, using:



sock.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)


But I want to replace this in a way I do it with ZMQ. Does the ZMQ really have a broadcast discovery in a different way or we should use the same code above as we do for regular broadcasting?










share|improve this question
















I am trying to use broadcasting packets to subnet address, I successfully tried to do that using socket's broadcast option, But I recently started learning ZeroMQ so I would like to use it to broadcast the packets to the subnet. I used zmq.PUB, zmq.SUB but at the subscriber side, the packets are undelivered because I use subnet address. If I use IP address of the machine then it works, but that's not what I want.



Is there any option for broadcasting using ZMQ?





Here is the code I tried so far:



Publisher:



import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://192.X.X.255:9999") # Note.

while True:
socket.send_string('hello')
time.sleep(1)




Subscriber:



context = zmq.Context()
sub=context.socket(zmq.SUB) # Note.
sub.setsockopt(zmq.SUBSCRIBE, b"") # Note.
sub.connect('tcp://192.x.x.255:9999') -> publishing only to subnet

while True:
print(sub.recv())




We can do the broadcasting of packets using a regular socket, for example, using:



sock.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)


But I want to replace this in a way I do it with ZMQ. Does the ZMQ really have a broadcast discovery in a different way or we should use the same code above as we do for regular broadcasting?







python sockets zeromq publish-subscribe pyzmq






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 20:20









Benyamin Jafari

3,19232243




3,19232243










asked Nov 24 '18 at 10:57









keerthanakeerthana

378




378













  • I don't know about "subnet address" meaning, but with using the .bind("tcp://*:1234") in publisher side, each subscriber could connect on it and get the message over ZMQ with .connect("tcp://publisher-ip:1234"), Isn't that what you are looking for?

    – Benyamin Jafari
    Nov 24 '18 at 20:29











  • Hi, Subnet address is the ip address and the broadcast address mix, for example only the ppl connect to the router wifi gets the message which we send. The address will look like 192.167.1.255, You can see in your ifconfig. So this will avoid sending message to all.(255.255.255.255) @Benyamin jafari . My publisher and subscriber both will use same subnet address. One to publish and other one to subscriber.

    – keerthana
    Nov 24 '18 at 20:32













  • Hi, I think still do not understand what you mean. So I will take an example as an answer, if it wouldn't help you, I'll remove it.

    – Benyamin Jafari
    Nov 24 '18 at 20:43











  • @BenyaminJafari The answer you posted might help only for the publisher who wants to publish to the whole network. "*" this means i think 255.255.255.255 address. Everyone can listen to the publisher, I want it to be private thats why i use subnet address. By the way if you could help, Apart from pub-sub or whatever messaging pattern, i really need to find a zmq way for broadcasting udp packet.

    – keerthana
    Nov 24 '18 at 20:49



















  • I don't know about "subnet address" meaning, but with using the .bind("tcp://*:1234") in publisher side, each subscriber could connect on it and get the message over ZMQ with .connect("tcp://publisher-ip:1234"), Isn't that what you are looking for?

    – Benyamin Jafari
    Nov 24 '18 at 20:29











  • Hi, Subnet address is the ip address and the broadcast address mix, for example only the ppl connect to the router wifi gets the message which we send. The address will look like 192.167.1.255, You can see in your ifconfig. So this will avoid sending message to all.(255.255.255.255) @Benyamin jafari . My publisher and subscriber both will use same subnet address. One to publish and other one to subscriber.

    – keerthana
    Nov 24 '18 at 20:32













  • Hi, I think still do not understand what you mean. So I will take an example as an answer, if it wouldn't help you, I'll remove it.

    – Benyamin Jafari
    Nov 24 '18 at 20:43











  • @BenyaminJafari The answer you posted might help only for the publisher who wants to publish to the whole network. "*" this means i think 255.255.255.255 address. Everyone can listen to the publisher, I want it to be private thats why i use subnet address. By the way if you could help, Apart from pub-sub or whatever messaging pattern, i really need to find a zmq way for broadcasting udp packet.

    – keerthana
    Nov 24 '18 at 20:49

















I don't know about "subnet address" meaning, but with using the .bind("tcp://*:1234") in publisher side, each subscriber could connect on it and get the message over ZMQ with .connect("tcp://publisher-ip:1234"), Isn't that what you are looking for?

– Benyamin Jafari
Nov 24 '18 at 20:29





I don't know about "subnet address" meaning, but with using the .bind("tcp://*:1234") in publisher side, each subscriber could connect on it and get the message over ZMQ with .connect("tcp://publisher-ip:1234"), Isn't that what you are looking for?

– Benyamin Jafari
Nov 24 '18 at 20:29













Hi, Subnet address is the ip address and the broadcast address mix, for example only the ppl connect to the router wifi gets the message which we send. The address will look like 192.167.1.255, You can see in your ifconfig. So this will avoid sending message to all.(255.255.255.255) @Benyamin jafari . My publisher and subscriber both will use same subnet address. One to publish and other one to subscriber.

– keerthana
Nov 24 '18 at 20:32







Hi, Subnet address is the ip address and the broadcast address mix, for example only the ppl connect to the router wifi gets the message which we send. The address will look like 192.167.1.255, You can see in your ifconfig. So this will avoid sending message to all.(255.255.255.255) @Benyamin jafari . My publisher and subscriber both will use same subnet address. One to publish and other one to subscriber.

– keerthana
Nov 24 '18 at 20:32















Hi, I think still do not understand what you mean. So I will take an example as an answer, if it wouldn't help you, I'll remove it.

– Benyamin Jafari
Nov 24 '18 at 20:43





Hi, I think still do not understand what you mean. So I will take an example as an answer, if it wouldn't help you, I'll remove it.

– Benyamin Jafari
Nov 24 '18 at 20:43













@BenyaminJafari The answer you posted might help only for the publisher who wants to publish to the whole network. "*" this means i think 255.255.255.255 address. Everyone can listen to the publisher, I want it to be private thats why i use subnet address. By the way if you could help, Apart from pub-sub or whatever messaging pattern, i really need to find a zmq way for broadcasting udp packet.

– keerthana
Nov 24 '18 at 20:49





@BenyaminJafari The answer you posted might help only for the publisher who wants to publish to the whole network. "*" this means i think 255.255.255.255 address. Everyone can listen to the publisher, I want it to be private thats why i use subnet address. By the way if you could help, Apart from pub-sub or whatever messaging pattern, i really need to find a zmq way for broadcasting udp packet.

– keerthana
Nov 24 '18 at 20:49












1 Answer
1






active

oldest

votes


















0














Suppose you have three Machines (M1, M2, M3) with three difference IP address with the same subnet and a defined port. We want publish a message (from M1) on each subscriber (M1, M2), so we would have the following snippet code:



Publisher (Machine1):



import zmq
import time

context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:9999") # Note.

while True:
socket.send_string('hello-all')
time.sleep(1)




Subscriber (Machine2):



context = zmq.Context()
sub=context.socket(zmq.SUB)
sub.setsockopt(zmq.SUBSCRIBE, b"")
sub.connect('tcp://Machine1_IP:9999') # Note

while True:
print(sub.recv())




Subscriber (Machine3):



context = zmq.Context()
sub=context.socket(zmq.SUB)
sub.setsockopt(zmq.SUBSCRIBE, b"")
sub.connect('tcp://Machine1_IP:9999') # Note

while True:
print(sub.recv())





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457415%2fbroadcasting-to-subnet-address-using-pyzmq%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Suppose you have three Machines (M1, M2, M3) with three difference IP address with the same subnet and a defined port. We want publish a message (from M1) on each subscriber (M1, M2), so we would have the following snippet code:



    Publisher (Machine1):



    import zmq
    import time

    context = zmq.Context()
    socket = context.socket(zmq.PUB)
    socket.bind("tcp://*:9999") # Note.

    while True:
    socket.send_string('hello-all')
    time.sleep(1)




    Subscriber (Machine2):



    context = zmq.Context()
    sub=context.socket(zmq.SUB)
    sub.setsockopt(zmq.SUBSCRIBE, b"")
    sub.connect('tcp://Machine1_IP:9999') # Note

    while True:
    print(sub.recv())




    Subscriber (Machine3):



    context = zmq.Context()
    sub=context.socket(zmq.SUB)
    sub.setsockopt(zmq.SUBSCRIBE, b"")
    sub.connect('tcp://Machine1_IP:9999') # Note

    while True:
    print(sub.recv())





    share|improve this answer




























      0














      Suppose you have three Machines (M1, M2, M3) with three difference IP address with the same subnet and a defined port. We want publish a message (from M1) on each subscriber (M1, M2), so we would have the following snippet code:



      Publisher (Machine1):



      import zmq
      import time

      context = zmq.Context()
      socket = context.socket(zmq.PUB)
      socket.bind("tcp://*:9999") # Note.

      while True:
      socket.send_string('hello-all')
      time.sleep(1)




      Subscriber (Machine2):



      context = zmq.Context()
      sub=context.socket(zmq.SUB)
      sub.setsockopt(zmq.SUBSCRIBE, b"")
      sub.connect('tcp://Machine1_IP:9999') # Note

      while True:
      print(sub.recv())




      Subscriber (Machine3):



      context = zmq.Context()
      sub=context.socket(zmq.SUB)
      sub.setsockopt(zmq.SUBSCRIBE, b"")
      sub.connect('tcp://Machine1_IP:9999') # Note

      while True:
      print(sub.recv())





      share|improve this answer


























        0












        0








        0







        Suppose you have three Machines (M1, M2, M3) with three difference IP address with the same subnet and a defined port. We want publish a message (from M1) on each subscriber (M1, M2), so we would have the following snippet code:



        Publisher (Machine1):



        import zmq
        import time

        context = zmq.Context()
        socket = context.socket(zmq.PUB)
        socket.bind("tcp://*:9999") # Note.

        while True:
        socket.send_string('hello-all')
        time.sleep(1)




        Subscriber (Machine2):



        context = zmq.Context()
        sub=context.socket(zmq.SUB)
        sub.setsockopt(zmq.SUBSCRIBE, b"")
        sub.connect('tcp://Machine1_IP:9999') # Note

        while True:
        print(sub.recv())




        Subscriber (Machine3):



        context = zmq.Context()
        sub=context.socket(zmq.SUB)
        sub.setsockopt(zmq.SUBSCRIBE, b"")
        sub.connect('tcp://Machine1_IP:9999') # Note

        while True:
        print(sub.recv())





        share|improve this answer













        Suppose you have three Machines (M1, M2, M3) with three difference IP address with the same subnet and a defined port. We want publish a message (from M1) on each subscriber (M1, M2), so we would have the following snippet code:



        Publisher (Machine1):



        import zmq
        import time

        context = zmq.Context()
        socket = context.socket(zmq.PUB)
        socket.bind("tcp://*:9999") # Note.

        while True:
        socket.send_string('hello-all')
        time.sleep(1)




        Subscriber (Machine2):



        context = zmq.Context()
        sub=context.socket(zmq.SUB)
        sub.setsockopt(zmq.SUBSCRIBE, b"")
        sub.connect('tcp://Machine1_IP:9999') # Note

        while True:
        print(sub.recv())




        Subscriber (Machine3):



        context = zmq.Context()
        sub=context.socket(zmq.SUB)
        sub.setsockopt(zmq.SUBSCRIBE, b"")
        sub.connect('tcp://Machine1_IP:9999') # Note

        while True:
        print(sub.recv())






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 20:50









        Benyamin JafariBenyamin Jafari

        3,19232243




        3,19232243
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457415%2fbroadcasting-to-subnet-address-using-pyzmq%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'