I'm learning how to use multicast UDP in Java language. I just studied the examples here.
However, after that I downloaded the codes and executed them, they work only if I run the multicast client and the multicast server in the same PC.
Hence, I tried to run multiple instance of the client and one instance of the server into a LAN network it did not work.
Finally, I deeply studied the code and take a look on the web and I found that it is correct.
My client is on GNU/linux ubuntu mate 16.04 LTS 64 bit while I tried to run other clients with same and different OS (also Windows).
I think that is not something related to OS configuration (on GNU/linux via ifconfig I saw multicast enabled), but it should be a problem of my local network. I configured the router in order to allow IGMP proxy and IGMP spoofing and I also disabled the firewall.
Then I used wireshark in order to capture the IGMP and UDP packages. I could see the client in my PC that send IGMP request to join the multicast group (address) and UDP data to the group while I could not receive any package.
What can I do?
My final goal is to test the code across Internet instead on my local LAN. Could an ISP block my multicast traffic?
Thank you
P.S.
I'm using reserved multicast IP
netstat -gn show that my network interface has joined the multicast group
Related
So I'd like an automated network discovery for the application I'm currently building, but turns out we're not in a perfect world and neither does every network have IPv6 enabled for multicasting, nor is IPv4 UDP broadcast enabled in every network.
Any idea how I can programmatically find out, if either of those are enabled in the current network? Since UDP doesn't open a connection, I can just throw datagrams and hope someone finds it, then if noone else answers after a set time (or like, offer the user a button for manual discovery from the beginning) use user provided information (or a name service / registry I'd have to host somewhere).
Looks like sending a multicast is received on my own machine when I send it from one port to the other, but I can't be sure it actually goes out of the device and back in or it just loops back because it's being clever.
I'd prefer multicast of course - broadcast would be the fallback here.
Update
Tried things in the eduroam network:
Made new MulticastSocket and joined the multicast using joinGroup.
Made new DatagramSocker and sent a message to that multicast group
-> Works locally
-> Doesn't work across machines
Same with broadcast (interfaceAddress.getBroadcast()). Works locally (Sending from one port to another), but not across machines.
So how do I programmatically decide if these work?
I have implemented a simple P2P multicast network where each peer connected to the network sends data to every other peer. In order to make it possible, I made use of Java MulticastSocket Class, so every peer joins a multicast group defined by an available for multicast IP address, and a port number.
I got some issues while trying to run the program using EC2 services, where each generated instance represents a peer of the network, because the peers are not able to communicate in so far as exchanged messages do not reach the receivers.
Hence, basically my question is: is there a way to make EC2 instances communicate to each other using Java MulticastSocket? Can anyone help?
Natively, you can't.
Q. Does Amazon VPC support multicast or broadcast?
No.
https://aws.amazon.com/vpc/faqs/
Same thing for EC2 Classic (though there is hardly any reason you'd ever want to use that, if your account even allows it).
VPC looks like Ethernet, but it isn't. Put a packet sniffer on and try a ping. Watch the ARP traffic on both sides and you'll see something enlightening -- the source machine arps for the target and gets a response, but you'll see neither of these packets on the target machine. The ARP response comes from the network infrastructure itself.
There's a workhackaround, if you're feeling crafty: you can build an overlay mesh network that transports multicast over unicast.
See https://aws.amazon.com/articles/6234671078671125
My issue is a protocol that identifies terminals by it's sending IP. I want to manage the connections of several terminals to this server using some kind of proxy that implements that protocol.
So I have Terminal A which is identified by the server by the IP 1.2.3.4 and Terminal B which is identified by the server using the IP 5.6.7.8. Now the proxy will be in a local network with Terminal A and B.
When Terminal A wants to reach the server, it will query the proxy and the proxy needs to send the request on behalf of Terminal A using IP 1.2.3.4 to the server
When Terminal B wants to reach the server, it will query the proxy and the proxy needs to send the request on behalf of Terminal A using IP 5.6.7.8 to the server
Is it even possible to solve that issue in Java or do I have to do network voodoo on the router to achieve this?
Edit: to make things clear. I know what a network proxy is and what a router does. I also know how to solve my problem on a network level using advanced network voodoo if required. What I want to know is if my guess that the problem can't be solved using Java is correct. So the bottom line question is: can I use Java to send traffic using a specific network interface to which a specific IP has been assigned or do I have to rely on what the operating system does to route my traffic (in which case the advanced network voodoo would be required)?
Edit2: If routing of network traffic can be done in java, I'd just like a quick pointer where to look into. My own googling didn't return any useful results.
1) You already have some implementations for tcp tunelling with java. Below are some examples:
http://jtcpfwd.sourceforge.net/
http://sourceforge.net/projects/jttt/
2) Even with these existing implementations, you can still do you own by forwarding packets arriving in the proxy using java.net.Socket.
3) I still think that a better option would be a specific implementation using java.lang.Runtime.exec() and socat linux command. socat is just like the Netcat but with security and chrooting support and works over various protocols and through a files, pipes, devices, TCP sockets, Unix sockets, a client for SOCKS4, proxy CONNECT, or SSL etc. To redirect all port 80 conenctions to ip 202.54.1.5:
$ socat TCP-LISTEN:80,fork TCP:202.54.1.5:80
Can I perform a UDP broadcast packets on my machine? I don't have a network, i just have my cheap linux box. I want to have a server broadcasting a packet and two or more clients in the same machine receiving them. Is that possible? What IP do I use?
#gravyface gave me hope but I tried: 1) server sending to 127.255.255.255:54321 and clients listenting to 0.0.0.0:54321. 2) server sending to 127.255.255.255:54321 and clients listening to 127.0.0.1:54321. 3) server sending to 127.255.255.255:54321 and clients listening to 127.255.255.255:54321. None of them worked! :(
OBS: I am using REUSE_ADDR and SO_BROADCAST options.
I am able to confirm that 127.255.255.255 works on Linux (Ubuntu) and it does not work on Mac (Snow Leopard). If you ever find out how to do that on Mac let me know. :)
You can use virtual network adapters with different virtual addresses. For example in Windows you can use Microsoft Loopback or TUN/TAP in Linux.
Another solution would be to create an internal network with a Virtualization software such as VirtualBox but this would require a slight faster machine. If you could only afford(since it's a cheap box) a single Virtual Machine you could enable 1-4 network adapters that would allow you to bind your different UDP clients individually on each one of the virtual adapters of your virtual device.
I have a windows XP machine having a single network adapter with 2 IP addresses (basically there are 2 subnets on the same physical network):
IP Address 1: 1.51.1.2 mask 255.255.0.0
IP address 2: 1.162.1.2 mask 255.255.255.0
Default Gateway: 1.51.1.1
My application which is written in java needs to communicate with other applications using IP multicast on say IP 224.0.5.1. However, this does not work as sound as I add the second IP address to the network adapter. I have done some digging with good old Wireshark and come to the conclusion that the IGMP join request is the problem. The source IP on the datagram is 1.51.1.2 in the case where it works and 1.162.1.2 when it does not. The gateway which is a router seem to ignore the join if the source is not on the same subnet as it itself is configured to be on. You could say that is somewhat fine (although the IGMP spec is a bit silent here), but I cannot see any way to actually influence the source IP of the datagram in any of the many socket APIs I have looked at so far. Everything seems to occur on the network interface with no regards to the actual subnet used.
Also strangely it seems that the source IP on the datagram is actually chosen to be the highest IP number which I guess is predictable but not exactly intuitive. So here are my questions:
Is there any way in Java or any of the native windows libraries to set the source IP on the UDP datagram of the IGMP request?
Is the fact that the gateway ignores the join because it does not recognise the source the correct behavior (I am going with de facto behavior as the spec is vague on this point)?
About a way to actually influence the source IP of the datagram:
SocketOptions.setOption(IP_MULTICAST_IF, InetAddress);
OR
MulticastSocket.setInterface(InetAddress)