Sending a String and Int in the same datagramPacket


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Sending a String and Int in the same datagramPacket

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Posts
    17

    Sending a String and Int in the same datagramPacket

    Hi

    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?

    Many Thanks

    Sam

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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

    http://java.sun.com/docs/books/tutor.../io/index.html

    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 09:18 AM.

Similar Threads

  1. Typedef Declaration in VB
    By floydus in forum VB Classic
    Replies: 7
    Last Post: 06-05-2006, 06:49 PM
  2. KeyListener not responding
    By lordanki in forum Java
    Replies: 3
    Last Post: 04-04-2006, 11:13 AM
  3. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 03:32 PM
  4. Producer Consumer Thread
    By Chirag in forum Java
    Replies: 6
    Last Post: 04-10-2002, 06:22 AM
  5. Replies: 1
    Last Post: 06-05-2001, 07:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center