Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Sockets, Bytes / Objects

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Sockets, Bytes / Objects

    Hello All,

    I'm new here to the Java programming forums, looks like a friendly place to get some advice.

    Please excuse any naivety on my part, I'm rather new to socket programming in Java, and I'm actually just getting back into Java itself.

    Basically I have a server / client setup and I need to transfer objects between the two.

    I can currently transfer bytes via a buffer buffer, but I need custom objects.

    What is the best method of transferring objects?

    1. Converting the object to a byte array?
    2. Using the object stream?
    3.. or some other method.

    Any advice would be great!


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java Sockets, Bytes / Objects

    Write the object to an ObjectOutputStream. Make sure the classes you wish to write implement Serializable, and any info you don't need to be written marked as transient.

Similar Threads

  1. reading stream of bytes from serial port
    By KrisTheSavage in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: January 3rd, 2011, 11:02 AM
  2. Reading an int from bytes(binary file) - HELP
    By yogiyogi in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 14th, 2010, 02:03 PM
  3. convert vector to array of bytes
    By chopficaro in forum Java Theory & Questions
    Replies: 1
    Last Post: May 3rd, 2010, 11:00 AM
  4. Java sockets help
    By ma05k1 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 27th, 2010, 05:52 AM
  5. How to Get the size of a file in bytes
    By JavaPF in forum File Input/Output Tutorials
    Replies: 1
    Last Post: June 8th, 2009, 10:19 AM