Creating a byte array to be sent over udp
843790Mar 6 2009 — edited Mar 9 2009Hey,
I am creating a mock packet system for a project and i need to send over a byte array filled with a. my ip address b. my port number and c. a message.
The problem I am having is converting the port number and ip address to the appropriate byte arrays. The text is simple because the string class as a getBytes() method. I have seen some function people have posted online for converting ints to byte arrays and vice versa but i was wondering if there were any other simpler built in method to do this. For exmaple with an ip address i would split the string into a byte array of size 4 and since each section of the address can be at most one byte big i dont need it to be an array, but all the methods just output a byte array. Any help would be greatly appreciated.
Thanks