Multicast between applications on the same host Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!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

What is a more techy Technical Writer job title that isn't cutesy or confusing?

Why can't fire hurt Daenerys but it did to Jon Snow in season 1?

Determine whether an integer is a palindrome

Marquee sign letters

How to ask rejected full-time candidates to apply to teach individual courses?

Pointing to problems without suggesting solutions

How does the body cool itself in a stillsuit?

Are there any irrational/transcendental numbers for which the distribution of decimal digits is not uniform?

Plotting a Maclaurin series

Diophantine equation 3^a+1=3^b+5^c

What are some likely causes to domain member PC losing contact to domain controller?

Keep at all times, the minus sign above aligned with minus sign below

Weaponising the Grasp-at-a-Distance spell

How could a hydrazine and N2O4 cloud (or it's reactants) show up in weather radar?

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

Improvising over quartal voicings

What helicopter has the most rotor blades?

.bashrc alias for a command with fixed second parameter

Why does BitLocker not use RSA?

Statistical analysis applied to methods coming out of Machine Learning

Is a copyright notice with a non-existent name be invalid?

Why not use the yoke to control yaw, as well as pitch and roll?

Understanding piped commands in GNU/Linux

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?



Multicast between applications on the same host



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved