Multicast between applications on the same hostDifferences between HashMap and Hashtable?What is the difference between public, protected, package-private and private in Java?Finding the multicast IP that a datagram was sent toJava multicast socket not received out of localhostMulticastSocket constructors and binding to port or SocketAddressJava multiple multicast sockets in same group on same host and portReceiving Unicast on Multicast socketJava UDP multicast, determine which group sent packetCan DatagramSocket Receive multicast PacketsJava Multicast receiver not working

Why can't we play rap on piano?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

What defenses are there against being summoned by the Gate spell?

"You are your self first supporter", a more proper way to say it

Codimension of non-flat locus

Theorems that impeded progress

How much RAM could one put in a typical 80386 setup?

Important Resources for Dark Age Civilizations?

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

Could an aircraft fly or hover using only jets of compressed air?

Definite integral giving negative value as a result?

Is it unprofessional to ask if a job posting on GlassDoor is real?

Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?

Why doesn't H₄O²⁺ exist?

How do I deal with an unproductive colleague in a small company?

Convert two switches to a dual stack, and add outlet - possible here?

Has there ever been an airliner design involving reducing generator load by installing solar panels?

Can I ask the recruiters in my resume to put the reason why I am rejected?

Why do I get two different answers for this counting problem?

Arrow those variables!

How old can references or sources in a thesis be?

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Was any UN Security Council vote triple-vetoed?

Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?



Multicast between applications on the same host


Differences between HashMap and Hashtable?What is the difference between public, protected, package-private and private in Java?Finding the multicast IP that a datagram was sent toJava multicast socket not received out of localhostMulticastSocket constructors and binding to port or SocketAddressJava multiple multicast sockets in same group on same host and portReceiving Unicast on Multicast socketJava UDP multicast, determine which group sent packetCan DatagramSocket Receive multicast PacketsJava Multicast receiver not working






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















From what I've read, it should be possible for two applications on the same host to be able to send and receive datagrams via multicast. I was trying to implement this, using the following Java code (which is a slightly modified version of what is given in the Javadoc for MulticastSocket):



 public static void main(String[] args) throws IOException

NetworkInterface nic = NetworkInterface.getByName("wlan4");

int port = 6789;
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(port);
s.setNetworkInterface(nic);
s.joinGroup(group);

if(args.length > 0 && args[0].equals("send"))
System.out.println("SEND MODE");
String msg = "Hello";
DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
group, port);
s.send(hi);
else

byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);




If I run the above code, giving send as input argument, the program executes just fine, it sends the packet and then terminates. However if I want to receive a packet, the program is blocked by the receive method as it never gets a datagram. I tested this by running multiple instances of the application on my machine, both with one and several receivers and one sender. Non gets any message at any time.



If I, on the other hand let the application receive what it just sent (by running the receive method unconditionally of wheter the application is sending), it works fine for that application alone. This triggers me to believe that the JVM instance has an exclusive bind on that socket, disallowing others to use it (even if the option getReuseAddress() returns true for MulticastSockets).



I'm running under Windows 10, and have verified that the UDP packet gets sent to the network using Wireshark, so I figured it has to do with that the packet is not delivered to the two applications.



What can I do in order to allow two applications to communicate over multicast on the same port number?



EDIT:



The overall idea is for a server to send a datagram to all listening clients on the network chosen (hence why the NIC is specified in the example as "wlan4"), irrespectively of where they are executed (e.g. on the same host as the server or not).










share|improve this question
























  • Why are you forcing the multicast socket to use wlan4 when all the required communication is within the localhost?

    – user207421
    Mar 9 at 2:14












  • Good point, and I realize that I might not have explained my overall intentions. The idea is for a sender to send a datagram to be caught by all clients on a network, irrespectively of whether the clients reside on the same host as the server or not.

    – chrillof
    Mar 9 at 13:21











  • Have you disabled multicast loopback? It seems to me that you are only receiving loopbacks, and that your joinGroup() hasn't taken effect outside your localhost at all. Try just removing the setNetworkInterface() line.

    – user207421
    Mar 10 at 23:40


















0















From what I've read, it should be possible for two applications on the same host to be able to send and receive datagrams via multicast. I was trying to implement this, using the following Java code (which is a slightly modified version of what is given in the Javadoc for MulticastSocket):



 public static void main(String[] args) throws IOException

NetworkInterface nic = NetworkInterface.getByName("wlan4");

int port = 6789;
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(port);
s.setNetworkInterface(nic);
s.joinGroup(group);

if(args.length > 0 && args[0].equals("send"))
System.out.println("SEND MODE");
String msg = "Hello";
DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
group, port);
s.send(hi);
else

byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);




If I run the above code, giving send as input argument, the program executes just fine, it sends the packet and then terminates. However if I want to receive a packet, the program is blocked by the receive method as it never gets a datagram. I tested this by running multiple instances of the application on my machine, both with one and several receivers and one sender. Non gets any message at any time.



If I, on the other hand let the application receive what it just sent (by running the receive method unconditionally of wheter the application is sending), it works fine for that application alone. This triggers me to believe that the JVM instance has an exclusive bind on that socket, disallowing others to use it (even if the option getReuseAddress() returns true for MulticastSockets).



I'm running under Windows 10, and have verified that the UDP packet gets sent to the network using Wireshark, so I figured it has to do with that the packet is not delivered to the two applications.



What can I do in order to allow two applications to communicate over multicast on the same port number?



EDIT:



The overall idea is for a server to send a datagram to all listening clients on the network chosen (hence why the NIC is specified in the example as "wlan4"), irrespectively of where they are executed (e.g. on the same host as the server or not).










share|improve this question
























  • Why are you forcing the multicast socket to use wlan4 when all the required communication is within the localhost?

    – user207421
    Mar 9 at 2:14












  • Good point, and I realize that I might not have explained my overall intentions. The idea is for a sender to send a datagram to be caught by all clients on a network, irrespectively of whether the clients reside on the same host as the server or not.

    – chrillof
    Mar 9 at 13:21











  • Have you disabled multicast loopback? It seems to me that you are only receiving loopbacks, and that your joinGroup() hasn't taken effect outside your localhost at all. Try just removing the setNetworkInterface() line.

    – user207421
    Mar 10 at 23:40














0












0








0








From what I've read, it should be possible for two applications on the same host to be able to send and receive datagrams via multicast. I was trying to implement this, using the following Java code (which is a slightly modified version of what is given in the Javadoc for MulticastSocket):



 public static void main(String[] args) throws IOException

NetworkInterface nic = NetworkInterface.getByName("wlan4");

int port = 6789;
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(port);
s.setNetworkInterface(nic);
s.joinGroup(group);

if(args.length > 0 && args[0].equals("send"))
System.out.println("SEND MODE");
String msg = "Hello";
DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
group, port);
s.send(hi);
else

byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);




If I run the above code, giving send as input argument, the program executes just fine, it sends the packet and then terminates. However if I want to receive a packet, the program is blocked by the receive method as it never gets a datagram. I tested this by running multiple instances of the application on my machine, both with one and several receivers and one sender. Non gets any message at any time.



If I, on the other hand let the application receive what it just sent (by running the receive method unconditionally of wheter the application is sending), it works fine for that application alone. This triggers me to believe that the JVM instance has an exclusive bind on that socket, disallowing others to use it (even if the option getReuseAddress() returns true for MulticastSockets).



I'm running under Windows 10, and have verified that the UDP packet gets sent to the network using Wireshark, so I figured it has to do with that the packet is not delivered to the two applications.



What can I do in order to allow two applications to communicate over multicast on the same port number?



EDIT:



The overall idea is for a server to send a datagram to all listening clients on the network chosen (hence why the NIC is specified in the example as "wlan4"), irrespectively of where they are executed (e.g. on the same host as the server or not).










share|improve this question
















From what I've read, it should be possible for two applications on the same host to be able to send and receive datagrams via multicast. I was trying to implement this, using the following Java code (which is a slightly modified version of what is given in the Javadoc for MulticastSocket):



 public static void main(String[] args) throws IOException

NetworkInterface nic = NetworkInterface.getByName("wlan4");

int port = 6789;
InetAddress group = InetAddress.getByName("228.5.6.7");
MulticastSocket s = new MulticastSocket(port);
s.setNetworkInterface(nic);
s.joinGroup(group);

if(args.length > 0 && args[0].equals("send"))
System.out.println("SEND MODE");
String msg = "Hello";
DatagramPacket hi = new DatagramPacket(msg.getBytes(), msg.length(),
group, port);
s.send(hi);
else

byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);




If I run the above code, giving send as input argument, the program executes just fine, it sends the packet and then terminates. However if I want to receive a packet, the program is blocked by the receive method as it never gets a datagram. I tested this by running multiple instances of the application on my machine, both with one and several receivers and one sender. Non gets any message at any time.



If I, on the other hand let the application receive what it just sent (by running the receive method unconditionally of wheter the application is sending), it works fine for that application alone. This triggers me to believe that the JVM instance has an exclusive bind on that socket, disallowing others to use it (even if the option getReuseAddress() returns true for MulticastSockets).



I'm running under Windows 10, and have verified that the UDP packet gets sent to the network using Wireshark, so I figured it has to do with that the packet is not delivered to the two applications.



What can I do in order to allow two applications to communicate over multicast on the same port number?



EDIT:



The overall idea is for a server to send a datagram to all listening clients on the network chosen (hence why the NIC is specified in the example as "wlan4"), irrespectively of where they are executed (e.g. on the same host as the server or not).







java network-programming multicast multicastsocket






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 10 at 23:09







chrillof

















asked Mar 9 at 0:59









chrillofchrillof

206




206












  • Why are you forcing the multicast socket to use wlan4 when all the required communication is within the localhost?

    – user207421
    Mar 9 at 2:14












  • Good point, and I realize that I might not have explained my overall intentions. The idea is for a sender to send a datagram to be caught by all clients on a network, irrespectively of whether the clients reside on the same host as the server or not.

    – chrillof
    Mar 9 at 13:21











  • Have you disabled multicast loopback? It seems to me that you are only receiving loopbacks, and that your joinGroup() hasn't taken effect outside your localhost at all. Try just removing the setNetworkInterface() line.

    – user207421
    Mar 10 at 23:40


















  • Why are you forcing the multicast socket to use wlan4 when all the required communication is within the localhost?

    – user207421
    Mar 9 at 2:14












  • Good point, and I realize that I might not have explained my overall intentions. The idea is for a sender to send a datagram to be caught by all clients on a network, irrespectively of whether the clients reside on the same host as the server or not.

    – chrillof
    Mar 9 at 13:21











  • Have you disabled multicast loopback? It seems to me that you are only receiving loopbacks, and that your joinGroup() hasn't taken effect outside your localhost at all. Try just removing the setNetworkInterface() line.

    – user207421
    Mar 10 at 23:40

















Why are you forcing the multicast socket to use wlan4 when all the required communication is within the localhost?

– user207421
Mar 9 at 2:14






Why are you forcing the multicast socket to use wlan4 when all the required communication is within the localhost?

– user207421
Mar 9 at 2:14














Good point, and I realize that I might not have explained my overall intentions. The idea is for a sender to send a datagram to be caught by all clients on a network, irrespectively of whether the clients reside on the same host as the server or not.

– chrillof
Mar 9 at 13:21





Good point, and I realize that I might not have explained my overall intentions. The idea is for a sender to send a datagram to be caught by all clients on a network, irrespectively of whether the clients reside on the same host as the server or not.

– chrillof
Mar 9 at 13:21













Have you disabled multicast loopback? It seems to me that you are only receiving loopbacks, and that your joinGroup() hasn't taken effect outside your localhost at all. Try just removing the setNetworkInterface() line.

– user207421
Mar 10 at 23:40






Have you disabled multicast loopback? It seems to me that you are only receiving loopbacks, and that your joinGroup() hasn't taken effect outside your localhost at all. Try just removing the setNetworkInterface() line.

– user207421
Mar 10 at 23:40













1 Answer
1






active

oldest

votes


















0














After some debugging, I realized that I could receive multicast packets from several applications if the application itself were sending and receiving multicast datagrams. It turns out that sending a packet to the multicast group somehow triggers this functionality. It seems like a bug to me.



However, in order to get the above example work as expected, I had to send (and discard) a first datagram to the multicast channel. I did this in the most simple way, by changing the else block to the following:



 byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.send(new DatagramPacket("A".getBytes(), 1, group, port));
s.receive(recv);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);





share|improve this answer























  • This doesn't seem right. NB You should use new String(recv.getData(), 0, recv.getLength()).

    – user207421
    Mar 10 at 23:41











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%2f55072968%2fmulticast-between-applications-on-the-same-host%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














After some debugging, I realized that I could receive multicast packets from several applications if the application itself were sending and receiving multicast datagrams. It turns out that sending a packet to the multicast group somehow triggers this functionality. It seems like a bug to me.



However, in order to get the above example work as expected, I had to send (and discard) a first datagram to the multicast channel. I did this in the most simple way, by changing the else block to the following:



 byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.send(new DatagramPacket("A".getBytes(), 1, group, port));
s.receive(recv);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);





share|improve this answer























  • This doesn't seem right. NB You should use new String(recv.getData(), 0, recv.getLength()).

    – user207421
    Mar 10 at 23:41















0














After some debugging, I realized that I could receive multicast packets from several applications if the application itself were sending and receiving multicast datagrams. It turns out that sending a packet to the multicast group somehow triggers this functionality. It seems like a bug to me.



However, in order to get the above example work as expected, I had to send (and discard) a first datagram to the multicast channel. I did this in the most simple way, by changing the else block to the following:



 byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.send(new DatagramPacket("A".getBytes(), 1, group, port));
s.receive(recv);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);





share|improve this answer























  • This doesn't seem right. NB You should use new String(recv.getData(), 0, recv.getLength()).

    – user207421
    Mar 10 at 23:41













0












0








0







After some debugging, I realized that I could receive multicast packets from several applications if the application itself were sending and receiving multicast datagrams. It turns out that sending a packet to the multicast group somehow triggers this functionality. It seems like a bug to me.



However, in order to get the above example work as expected, I had to send (and discard) a first datagram to the multicast channel. I did this in the most simple way, by changing the else block to the following:



 byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.send(new DatagramPacket("A".getBytes(), 1, group, port));
s.receive(recv);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);





share|improve this answer













After some debugging, I realized that I could receive multicast packets from several applications if the application itself were sending and receiving multicast datagrams. It turns out that sending a packet to the multicast group somehow triggers this functionality. It seems like a bug to me.



However, in order to get the above example work as expected, I had to send (and discard) a first datagram to the multicast channel. I did this in the most simple way, by changing the else block to the following:



 byte[] buf = new byte[1000];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
s.send(new DatagramPacket("A".getBytes(), 1, group, port));
s.receive(recv);

System.out.println("RECEIVE MODE");
s.receive(recv);
System.out.println(MessageFormat.format("Received: 0",
new String(recv.getData()).trim()));

s.leaveGroup(group);






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 10 at 23:09









chrillofchrillof

206




206












  • This doesn't seem right. NB You should use new String(recv.getData(), 0, recv.getLength()).

    – user207421
    Mar 10 at 23:41

















  • This doesn't seem right. NB You should use new String(recv.getData(), 0, recv.getLength()).

    – user207421
    Mar 10 at 23:41
















This doesn't seem right. NB You should use new String(recv.getData(), 0, recv.getLength()).

– user207421
Mar 10 at 23:41





This doesn't seem right. NB You should use new String(recv.getData(), 0, recv.getLength()).

– user207421
Mar 10 at 23:41



















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%2f55072968%2fmulticast-between-applications-on-the-same-host%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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page