title: How to repair BindException: Cannot assign requested address?
body: <p>I need to change the IP address of a host from a client.
  I use UDP commands and a MulticastSocket to obtain the IP address of this host (currentIp) and use this IP address to successfully establish a TCP connection.
  The command to change this host IP address requires a DatagramSocket since I need to first get the host device MAC address to include in the change IP address command. Once the TCP connection is made I close the MulticastSocket UDP socket so I can open the DatagramSocket but get the following error:</p>
  
  <blockquote>
    <p>java.net.BindException: Cannot assign requested address: Cannot bind</p>
  </blockquote>
  
  <p>Is there something I need to do besides close the MulticastSocket socket before trying to get a DatagramSocket socket with the same port number, or is am I missing something else? </p>
  
  <pre><code>DatagramSocket socket;
  private boolean ChangeIpAddress(String newIp) {
      DatagramSocket socket;
      try {
          socket = new DatagramSocket(30718, InetAddress.getByName(currentIp));
      } catch (SocketException ex) {
          ...
  </code></pre>