title: JAVA set / choose specific NIC from multiple (UDP)
body: <p>I am trying to send UDP with datagram in JAVA and my machine have several NIC with different IP's.</p>
  
  <p>How can I set which NIC I want my packet to be sent from ?? (assuming I have more than one on the machine ??)</p>
  
  <p>EDIT I</p>
  
  <p>I am not using Socket, I am using DatagramSocket and tried to do binding like so:</p>
  
  <pre><code>/*binding */
          DatagramSocket ds = new DatagramSocket(1111);
          NetworkInterface nif = NetworkInterface.getByIndex(nicIndex);
          Enumeration&lt;InetAddress&gt; nifAddresses = nif.getInetAddresses();
          ds.bind(new InetSocketAddress(nifAddresses.nextElement(), 0));
  </code></pre>
  
  <p>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..</p>
  
  <p>EDIT II</p>
  
  <p>For Clarification . 
  This App is a server - and the SERVER has 2 NICS . one LAN and one for WAN.</p>
  
  <p>An alternative way for me would to specify a ROUTING somehow - meaning to tell each packet exactly which NIC to use .. </p>
  
  <p>How to do such a routing in JAVA ??</p>