We help IT Professionals succeed at work.
Get Started

InetAddress errors

CrazyOne
CrazyOne asked
on
439 Views
Last Modified: 2014-05-01
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
Top Expert 2013
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE