Link to home
Start Free TrialLog in
Avatar of CrazyOne
CrazyOneFlag for United States of America

asked on

InetAddress errors

I have an array list of string arrays. In the string arrays is the IP address extracted from  a Datagram sent by a host. The value that is put into the string array is precisely the same as it arrived from the Datagram. However when I try to use the IP address from the string array I get an error.

for (int i = 0; i < listOfArrays.size(); i++) {
         String[] host = listOfArrays.get(i);
         System.out.println("ARRAY: " + host[0]);
         InetAddress hostAddr = InetAddress.getByName(host[0] );
         udpPcktSend = new DatagramPacket(bufYESSS, bufYESSS.length, hostAddr, Integer.parseInt(host[hPort].toString()));
         udpServerSocket.send(udpPcktSend);
      }

Open in new window

With this error happening on this line of code
InetAddress hostAddr = InetAddress.getByName(host[0] );
Exception in thread "main" java.net.UnknownHostException: "/192.168.1.17"
      at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
      at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
      at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
      at java.net.InetAddress.getAllByName0(InetAddress.java:1246)
      at java.net.InetAddress.getAllByName(InetAddress.java:1162)
      at java.net.InetAddress.getAllByName(InetAddress.java:1098)
      at java.net.InetAddress.getByName(InetAddress.java:1048)
      at CSMA_CH_SS.main(CSMA_CH_SS.java:102)

It worked yesterday now it is not. Now if I do the following and use the variable "address" it works fine and the IP address in both cases is the same.

udpPacketRcv = new DatagramPacket(buf, buf.length);
         udpServerSocket.receive(udpPacketRcv);
         fromClient = new String(udpPacketRcv.getData(), 0, udpPacketRcv.getLength()); 
         address = udpPacketRcv.getAddress();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of chaau
chaau
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CrazyOne

ASKER

DOH. I didn't think it was that simple. I noticed the slash, but I thought it was suppose to belong there because that is what was extracted from the Datagram.
Thanks