Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8271385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:49:35+00:00 2026-06-08T06:49:35+00:00

Hello,I’m developing a server which is using Netty.The goal is to be able to

  • 0

Hello,I’m developing a server which is using Netty.The goal is to be able to send objects back and forth.So I configured the server with using ObjectDecoderInputStream and ObjectEncoderOutputStream.

so I have a client also using Netty to communicate with the server. The client work well.

Whenever I use Java’s socket to receive an Serializable Object from the server. Something strange happened, I got an exception below:

java.io.StreamCorruptedException: Unsupported version: 0
at org.jboss.netty.handler.codec.serialization.CompactObjectInputStream.readStreamHeader(CompactObjectInputStream.java:38)
at java.io.ObjectInputStream.<init>(Unknown Source)
at org.jboss.netty.handler.codec.serialization.CompactObjectInputStream.<init>(CompactObjectInputStream.java:30)
at org.jboss.netty.handler.codec.serialization.ObjectDecoderInputStream.readObject(ObjectDecoderInputStream.java:115)
at com.bvd.main.Client.readResponse(Client.java:139)
at com.bvd.main.Client.getFile(Client.java:80)
at com.bvd.main.Client.main(Client.java:163)

Sending an object from the client:

    public static void writeRequest(Message requestMsg,
        OutputStream outputStream) {
    byte[] bytes = null;
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    try {
        ObjectEncoderOutputStream objectOutputStream = new ObjectEncoderOutputStream(
                byteOutputStream, 8192);
        objectOutputStream.writeObject(requestMsg);
        objectOutputStream.flush();
        bytes = byteOutputStream.toByteArray();
        byteOutputStream.close();
        objectOutputStream.close();
        outputStream.write(bytes);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

and the code that the client received an object:

    public static Object readResponse(InputStream inputStream) {
    int count = 0;
    Object object = null;
    try {
        byte[] lenBuffer = new byte[4];
        while ((count = inputStream.read(lenBuffer)) < 4) {
        }
        System.out.println(ByteBuffer.wrap(lenBuffer).getInt());
        int infolen = ByteBuffer.wrap(lenBuffer).getInt();
        byte[] objBuffer = new byte[infolen];
        while ((count = inputStream.read(objBuffer)) < infolen) {
        }
        byte[] totalBuf = new byte[4 + infolen];
        System.arraycopy(lenBuffer, 0, totalBuf, 0, lenBuffer.length);
        System.arraycopy(objBuffer, 0, totalBuf, lenBuffer.length,
                objBuffer.length);

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
                totalBuf);
        System.out.println(byteArrayInputStream.available());
        ObjectDecoderInputStream objectDecoderInputStream = new ObjectDecoderInputStream(
                new BufferedInputStream(byteArrayInputStream));
        object = objectDecoderInputStream.readObject();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return object;
}

What confuse me more is when I set the length of an object’s content being sent(the object carries part of a file that have been converted to byte[])on the server of 2858(byte), the client above works well; and when I change the length 2859 or bigger, the StreamCorruptedException occurs above.

ps: sending objects work well, the server received successfully and decode it correctly, all the questions are about objects receiving from the server.

Sorry for my poor English, any help is appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:49:37+00:00Added an answer on June 8, 2026 at 6:49 am

    in both of your read loops your are going to get bogus data if you end up making more than one read call:

        while ((count = inputStream.read(lenBuffer)) < 4) {
        }
    
    
        while ((count = inputStream.read(objBuffer)) < infolen) {
        }
    

    every time you call read, it will write to the beginning of the byte[]. so each time you loop around, you are overwriting part of the data in the buffer, not reading an entire buffer’s worth of data. you need to keep track of the current offset (based on the amount of data you have read so far) and pass that into thread read() call. also, you should be accumulating to count, not assigning to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone, I'm developing a photo sharing web site using the CodeIgniter PHP framework
Hello I have strange problem. I configured spring + hibernate. I`m using annotation configuration
Hello! I've been programming for a long time but just started developing for android,
hello all i am working on a project in which i have a webpage
Hello I've got this query to get users by email, which is an unique
Hello , I am using arshaw fullcalendar v1.5.2 (only month view ) for property
Hello everyone i am developing an quiz based app in android and i have
Hello,I'd like to ask you two questions. (I am using java and jedis) I
Hello I am trying to create a stacked barplot using the following code: test
Hello my Japplet is using a JComboBox and 5 JRadioButtons to draw and paint

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.