Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Creating a byte array to be sent over udp

843790Mar 6 2009 — edited Mar 9 2009
Hey,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2009
Added on Mar 6 2009
12 comments
1,170 views