I am creating a chat application using java sockets programming. I want to launch it in my local network which means my application doesn’t require internet to run. I tested the application on my computer itself by using the
InetAddress.getLocalHost();
method to create an Inetaddress object of my ip address.
Now the problem comes when i want to create this object with some other ip address in the local network..
After some experimenting i came to know that there is another function Inetaddress.getbyAddress(byte[]);
which takes byte array as ip address argument. Now if i want to create an
InetAddress object of an ip address say
192.168.234.190 i am not able to… since the .
byte array holds only values up to 127!!
what to do?
thanks in advance…
You could use
InetAddress.getByName("192.168.234.190");or if you really want to use getByAdress:The IP can be stored like this:
Now you have the IP in the array of bytes named IP and you could call multiple times
InetAddress.getByAddress(IP);