I am trying to send UDP with a datagram to JAVA, and my machine has several network adapters with different IP addresses.
How can I establish which network adapter I want to send from my package? (assuming I have more than one in my car?)
EDIT I
I do not use Socket, I use DatagramSocket and try to bind like this:
DatagramSocket ds = new DatagramSocket(1111); NetworkInterface nif = NetworkInterface.getByIndex(nicIndex); Enumeration<InetAddress> nifAddresses = nif.getInetAddresses(); ds.bind(new InetSocketAddress(nifAddresses.nextElement(), 0));
But when I do this, I can no longer connect (or cannot receive the packet ..). The problem is that I have 2 network adapters, but one for the INTERNAL network, and the other for the Internet. I need all the data on my server to be accessible only in the INTERNAL machine.
EDIT II
To clarify. This application is a server - and SERVER has 2 NICS. one LAN and one for WAN.
An alternative way for me - to specify ROUTING in some way - means to tell each packet which network adapter to use.
How to make such routing in JAVA ??
source share