Sending a String and Int in the same datagramPacket
I am trying to send a String and an Int number over a UDP socket in a byte array using a DatagramPacket to a server program from a client program. On the server end I need to split the byte array up and change the value of the Int number and then resend the String and Int back to the client. How can I send an Int number and a String in the same byte array, and then separate them at the server end?
Have you looked at creating a Packet (or some other name) class with these two fields, and make the class Serializable - able to be written to a stream, transmitted, and then reconstructed. Begin your research at
You can write your serialized class to a ByteArrayOutputStream to create the byte for your DatagramPacket. Reconstruct at the other end with a ByteArrayInputStream.
Last edited by nspils; 11-03-2006 at 08:18 AM.
By floydus in forum VB Classic
Last Post: 06-05-2006, 05:49 PM
By lordanki in forum Java
Last Post: 04-04-2006, 10:13 AM
By mdengler in forum ASP.NET
Last Post: 11-26-2002, 02:32 PM
Last Post: 04-10-2002, 05:22 AM
By Fred Mayes in forum Java
Last Post: 06-05-2001, 06:12 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center