InetAddress errors

CrazyOne
CrazyOne used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013
Commented:
There is a forward slash "/" in front of the IP address. May be that is why it is crashing. Try to remove the "/" from the string and test again

Author

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial