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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:36:06+00:00 2026-06-06T11:36:06+00:00

From PC (server side) the C#.Net application has to sent 22000 bytes of data

  • 0

From PC (server side) the C#.Net application has to sent 22000 bytes of data to an Android device (client side) via Wi-Fi. But dataInputStream in Android device is showing only 2048 bytes of it.

dataInputStream = new DataInputStream(workerSocket.getInputStream());
byte[] rvdMsgByte = new byte[dataInputStream.available()];
for (int i = 0; i < rvdMsgByte.length; i++)
    rvdMsgByte[i] = dataInputStream.readByte();
String rvdMsgStr = new String(rvdMsgByte);

I am confused with the following:

  1. Is PC can send only 2048 bytes of data?
  2. Or, is Android device has only 2048 bytes of capacity to receive data?
  3. Or, Does dataInputStream shows only 2048 bytes even after device received all bytes?

    If (data_received <= 2048 bytes)
    Above code works perfect;

  • 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-06T11:36:08+00:00Added an answer on June 6, 2026 at 11:36 am

    You basically shouldn’t be using InputStream.available(). That tells you how much data is available right now – which may well not be the whole message, if it’s still coming over the network.

    If the stream will end at the end of the message, you should simply keep looping, reading a block at a time until you’re done (preferrably not just reading a byte at a time!). For example:

    byte[] readFully(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buffer = new byte[8 * 1024]; // 8K buffer
        int bytesRead;
        while ((bytesRead = input.read(buffer)) > 0) {
            output.write(buffer, 0, bytesRead);
        }
        return output.toByteArray();
    }
    

    If you need to break your stream up into messages, you should consider how to do that – sending a “message length” prefix before the data is usually the best option.

    Once you’ve read all the data, you should not do this:

    String rvdMsgStr = new String(rvdMsgByte);
    

    That will use the platform default encoding to convert the bytes into text. If this is genuinely text data, you should use the string constructor overload which lets you specify the encoding explicitly.

    If it’s not genuinely text data, you shouldn’t be trying to treat it as such. If you really need to represent it as a string, use base64.

    Also note that there’s no need to use DataInputStream here, as far as I can tell.

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

Sidebar

Related Questions

I'm writting a client(Android) - server(c#) application. I get the code from here: How
How does one pass string contains '\' from from asp.net server side to javascript
Microsoft recommends their Script Encoder to encode asp.net scripts on server side from nosy/prying
im want to send notification from my server side (c#) via urbanairship api is
I need to create Client/Server application to send files from clients to Server. I
I have got a .NET WCF client talking to a Java server component. Server-side
I currently have a client-server application that involves a Silverlight client and a .NET
I have an application where a client communicates with a server side through REST.
In my ASP.Net page, I am loading data from server while scrolling using jQuery
How to close jQuery thickbox from server side - I want to cause the

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.