I currently am trying to create a chat server as an assignment and want each message to contain a header. It will contain ipv4 address followed by a letter then a username
I can easily decode string letters from bytes but now I am struggling to decode an ipv4 address from bytes
the representation so far from the bytes is this
[-64, -88, 1, 5]
which in the ipv4 dotted quad format would be 192.168.1.5
I just need a way to try and decode the four bytes of integers to a string or something along those lines
THANKS :D
One method is to create a string variable and then append the byte value to the string variable with the help of + operator. This will directly convert the byte value to a string and add it in the string variable. The simplest way to do so is using valueOf() method of String class in java.
Use int.Call int. to_bytes(length, byteorder) on an int with desired length of the array as length and the order of the array as byteorder to convert the int to bytes. If byteorder is set to "big" , the order of most significant bytes starts at the beginning of the array.
InetAddress.getByAddress(bytes).getHostAddress()
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With