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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:58:35+00:00 2026-06-12T21:58:35+00:00

I’m trying to read an object from client program over tcp. As you can

  • 0

I’m trying to read an object from client program over tcp. As you can see in this line I created objectInput:

ObjectInputStream objectInput = new ObjectInputStream(incoming.getInputStream());

And then read my input from the other program. It used to work fine until i made minor changes to clean up the program. Personally Assume I added

objectInput.clsoe();

My question is, After reading the object should I close the objectInputStream or Keep remain without close? Should I close it straight away after using it or at the end of if block or at the end of program? What are the effect of the close? By the way I have read the close documentation.

Here is the error:

java.io.EOFException
    at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
    at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    at Server.ClientWorker.run(MyCollectionServer.java:116)
    at java.lang.Thread.run(Thread.java:680)

Here is my code:

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        try 
        {
            serverSocket = new ServerSocket(port);  
        } 
        catch (IOException e) 
                {
            e.printStackTrace();
        }
        while(true)
        {   
            ClientWorker w;
            try
            {   
                w = new ClientWorker(serverSocket.accept());
                Thread t = new Thread(w);
                t.start();
            }
            catch(IOException e)
            {
                e.printStackTrace();
                break;
            }   
        }
    }
}

class ClientWorker implements Runnable
{
.....
    private Socket incoming;
    public ClientWorker(Socket incoming)
    {
        myList = new ArrayList<PureAlbum>();
        loadList();
        this.incoming = incoming;
    }

.....
    public synchronized  void run()
    {

else if(request.compareTo("AddAlbum")==0)
        {
            try
            {
                ObjectInputStream objectInput = new ObjectInputStream(incoming.getInputStream()); //This is the line mentioned in the error
                PureAlbum object = (PureAlbum) objectInput.readObject();


                if(object instanceof CDAlbum)
                {
                    CDAlbum a = (CDAlbum) object;
                    myList.add(a);
                    System.out.println("Artist = " + a.getArtist());
                }
                else if(object instanceof Client.au.edu.uow.Collection.DVDAlbum)
                {
                    myList.add((DVDAlbum) object);              
                }
                else
                {
                    System.err.println("Warning : The object to add to database is unknown! "+ object.getClass() + "*");
                    System.exit(0);
                }


            }
            catch (UnknownHostException e) 
            {
                System.err.println("Can not read the host name");
                e.printStackTrace();
            } 
            catch (IOException e) 
            {
                System.err.println("Can not read the FILE name"); //This exception has been called
                e.printStackTrace(); 
            }
            catch (ClassNotFoundException e) 
            {
                e.printStackTrace();
            }
        }
  • 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-12T21:58:36+00:00Added an answer on June 12, 2026 at 9:58 pm

    This line of stack trace shows that the exception is occurring when you are initializing the ObjectInputStream, not when you are closing.

    at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
    

    The most likely cause is that the remote client did not open an ObjectOutputStream. It might have written some other kind of data, or it might have closed its output stream or simply exited.

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,

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.