Avatar of CrazyOne
CrazyOne
Flag 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

Java

Avatar of undefined
Last Comment
CrazyOne

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
chaau

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy