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()));

Open in new window

With this error happening on this line of code
InetAddress hostAddr = InetAddress.getByName(host[0] );
Exception in thread "main" "/"
      at Method)
      at CSMA_CH_SS.main(

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);
         fromClient = new String(udpPacketRcv.getData(), 0, udpPacketRcv.getLength()); 
         address = udpPacketRcv.getAddress();

Open in new window

Avatar of chaau
Flag of Australia image

Link to home
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


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.