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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:40:30+00:00 2026-05-27T01:40:30+00:00

I am working on a server which reads data sent by the client, but

  • 0

I am working on a server which reads data sent by the client, but the size is not known neither can I change the client to send the size.

I want to read the data from client till it blocks and waits for server’s response. I tried using available(), it works sometimes but sometimes it just returns zero even when there’s some data in stream.

while((len = in.available()) != 0)
    in.read(b,0,len);

Is there any way to do this in Java? I’m aware of asynchronous methods, but have never tried that, so if someone can provide a short example.

  • 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-05-27T01:40:31+00:00Added an answer on May 27, 2026 at 1:40 am

    Using available() is the only way to do it without resorting to asynchronous methods.

    You don’t really need to rely on the value returned by available(); just check that there is “some” data available to make sure that read will not block. You must, however, check the value returned by read (the actual number of bytes read into the array):

    // Process all data currently available
    while (in.available() != 0)
    {
        int nb = in.read(b);
        // Process nb bytes
    }
    

    Note that available returning 0 does not mean that the end of the data was reached — it merely means that there is no data available for immediate consumption (data may become available in the next millisecond). Thus you’ll need to have some other mechanism in order for the server to know that the client will not send any more data and is waiting for a response instead.

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

Sidebar

Related Questions

I am working on an android client which reads continues stream of xml data
I am working on a server application which receives data over a TCP socket
we have WinForms app which stores data in SQL Server (2000, we are working
I am working on ASP application that reads data from sql server and displays
I deployed my working package on server which is enterprise edition, SSIS installed on
I am working on a product that runs an SQL server which allows some
I'm working on a Linux based server system in which there are two network
I am working on Windows Server 2003 (IIS6), which has two asp.net sites running
I have code which as been working against an older Active Directory server and
Cdonts is not working in server 2008 (im using 32bit) i tried copying cdonts.dll

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.