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

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme