I am trying to send UDP with datagram in JAVA and my machine have several NIC with different IP's.
How can I set which NIC I want my packet to be sent from ?? (assuming I have more than one on the machine ??)
EDIT I
I am not using Socket, I am using DatagramSocket and tried to do binding like so:
/*binding */
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 so, I can not connect anymore (or can not get the packet ..). The problem is that I have 2 NIC, but one is for INTERNAL network and the other one is for Internet .. I need all my server data to go only on the INTERNAL one..
EDIT II
For Clarification . This App is a server - and the SERVER has 2 NICS . one LAN and one for WAN.
An alternative way for me would to specify a ROUTING somehow - meaning to tell each packet exactly which NIC to use ..
How to do such a routing in JAVA ??