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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:45:39+00:00 2026-06-18T14:45:39+00:00

I have a simple Client/Server app. The server is set up so that if

  • 0

I have a simple Client/Server app. The server is set up so that if no data comes in within N seconds a timeout occurs and the socket connection is closed. I do this via Socket.setSoTimeout(). That all works fine if the client hangs. If the clients dies, though (e.g. I kill it with Ctrl-C), then readLine() never times out.

Here’s the server code, if that makes a difference:

public void run()
{
    PrintWriter out = null;
    BufferedReader in = null;

    try {
        sock.setSoTimeout(10000);

        out = new PrintWriter(sock.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(sock.getInputStream()));

        String input;
        while ((input = in.readLine()) != null) {

I’ve tried putting in a signal handler into the client to send an ABEND message over to the server but that’s not working (I suspect the socket gets closed before the ABEND is sent, but I haven’t really spent any time trying to figure that out).

Is there a way to wake up periodically and check the socket state to see if it’s closed? Or (better yet) not have readLine() hang if the socket closes? Should I be using an unbuffered reader of some sort? Does an unbuffered reader supporting a readLine-like mechanism exist?

I am using Java 6 on Linux.

EDIT: I’m killing the client myself during an idle period; all data has been sent and received at this point. I have verified (via ps) that the client program is no longer running; the Java process has indeed been killed. Using netstat I can see that the socket is closed, on both ends, yet readLine() still hangs.

  • 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-18T14:45:40+00:00Added an answer on June 18, 2026 at 2:45 pm

    I think you have misdiagnosed the problem.

    If the input side of the socket has been closed, then the readLine() call should see that close. After all buffered data has been consumed, the call should return a null. (You won’t get an IOException if the socket is closed normally, but you could get one if the connection times out … for example.)

    The most obvious explanation is that the socket has not been closed yet. Take a look at the circumstances in which the other end will close the socket, and figure out why this hasn’t happened yet.


    None of these is the solution, but I’ll answer for completeness.

    Is there a way to wake up periodically and check the socket state to see if it’s closed?

    Another thread could do that, but not this one.

    Or (better yet) not have readLine() hang if the socket closes?

    That’s what is supposed to happen.

    Should I be using an unbuffered reader of some sort?

    It wouldn’t help. You’d end up having to implement readLine() yourself, and your code would block at the same point. The blocking behaviour is happening below the buffering and character decoding layers of the reader chain.

    Does an unbuffered reader supporting a readLine-like mechanism exist?

    No it doesn’t. See above.

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

Sidebar

Related Questions

I have a simple client-server app on android. the android service communicates with the
I have created my web socket server and client using this simple tutorial here
I have a simple console app that clients will install on their server which
We have a huge client/server WinForms app that uses .NET remoting to pass DAOs
I have a simple client/server setup. The server is in C and the client
Say I have a simple client/server scenario with one method: // client code $client
I have a simple UDP client server written in C++ on Ubuntu 9.10 where
I have a somewhat simple Client/Server solution running over C# remoting (System.Runtime.Remoting). The MarshalByRef
I am trying to learn WCF. I have a simple client and server application
I have client/server applications and a very simple protocol for communication. More precisely, it's

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.