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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:44:55+00:00 2026-06-11T03:44:55+00:00

Two computers are connected by socket connection. If the server/client closes the connection from

  • 0
  1. Two computers are connected by socket connection. If the server/client closes the connection
    from their end(i.e closes the InputStream, OutputStream and Socket) then how can I inform
    the other end about the disconnection? There is one way I know of – trying to read from the InputStream,
    which throws an IOException if connection is closed, but is there any other way to detect this?
  2. Another question, I looked the problem up on the internet and saw inputStream.available()
    does not solve this problem. Why is that?

Additional Information : I’m asking for another way because my project becomes tough to handle if I have to try to read from the
InputStrem to detect a disconnection.

  • 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-11T03:44:56+00:00Added an answer on June 11, 2026 at 3:44 am

    trying to read from the InputStream, which throws an IOException

    That is not correct. If the peer closes the socket:

    • read() returns -1
    • readLine() returns null
    • readXXX() throws EOFException, for any other X.

    As InputStream only has read() methods, it only returns -1: it doesn’t throw an IOException at EOS.

    Contrary to other answers here, there is no TCP API or Socket method that will tell you whether the peer has closed the connection. You have to try a read or a write.

    You should use a read timeout.

    InputStream.available() doesn’t solve the problem because it doesn’t return an EOS indication of any kind. There are few correct uses of it, and this isn’t one of them.

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

Sidebar

Related Questions

Is it possible to have two computers socket-connect to each other without any server
I'm having issues getting a simple server/client socket app working in C# between two
I want to know how two computers with VoIP software can be connected to
I have long-lasting TCP connection between two computers (second not under my control). Second
I have seen new computers having two processors on same motherboard . How can
I've written two functions, which should start a TCP-Server/Client. If I call them with
I installed SQL Server 2005 express on two computers. I installed SQL Server Management
My problem is that I can't connect two computers via sockets (windows xp and
I'm making two programs; a server application (single instance), and a client application (multiple
What are the basic principles of how two separable computers connected within the same

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.