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 8835741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:19:42+00:00 2026-06-14T09:19:42+00:00

I have a question about reading bytes from server socket. I’m using the default

  • 0

I have a question about reading bytes from server socket.
I’m using the default values ​​for literacy 8192b bytes on the network.
The problem is that there are times you need to send files larger than the buffer capacity.
To avoid increasing the buffer as you can know that those packets arriving at different times are related?

Client side snippet:

{
String c = xxxxx //imagine that it an string format JSON with 64000bites length
OutputStream wsOS = socket.getOutputStream();
wsOS.write(new String(data,"UTF-8"));
wsOS.flush();
}

When server side received the JSON string:

{

 byte[] buffer = new byte[8192];
 int size = 0;

 StringBuilder str = new StringBuilder();

 size = wsIS.read(buffer);

if (size > 0) {

    str.append(new String(buffer, "UTF-8")
            .substring(0, size));

    while (wsIS.available() > 0) {
        size = wsIS.read(buffer);
        str.append(new String(buffer, "UTF-8")
                .substring(0, size));
    }

}
}

Problem:

All string arrived in the server but in block 8192b – I can not concatenate the string because I don’t know if the last string JSON is part of the previews.

  • 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-14T09:19:43+00:00Added an answer on June 14, 2026 at 9:19 am

    Even if you increase the buffer size there is no guarantee that the whole string will be read in a single call to wsIS.read.

    What this means is that you must have some mechanism to know where the previous string has ends and new one begins. Some choices are as follows:

    1. Use ObjectOutputStream / ObjectInputStream
    2. Write number of characters before actually writing the characters. On the reading side, read the length and then those many chars
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading a description about swapping pointer addresses on Stackoverflow, I have a question
I have a question about this formula from a book: EFW (cm,kg)= 10^(-1,7492+(0,166*BPD)+(0,046*AC)-(2,646*AC*BPD/1000)) The
I've just started reading C and have a question about a macro. How can
After reading alot about VTables, I still have one unanswered question. Given the next
I'm reading a book about Ruby/Rails and have a question about something simple. In
I have for a few days reading this and other tutorials about javax.crypto Using
I have a few questions about this after reading the iPhone documentation on it:
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all

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.