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:
java.net.BindException: Cannot assign requested address: Cannot bind
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?
DatagramSocket socket;
private boolean ChangeIpAddress(String newIp) {
DatagramSocket socket;
try {
socket = new DatagramSocket(30718, InetAddress.getByName(currentIp));
} catch (SocketException ex) {
...