Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: EOFException on sending object

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    13
    My Mood
    Cool
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy EOFException on sending object

    Dear all,

    I've been struggeling with this issue for days now and I'm completely stuck on this.
    The thing what I want to do is send an object over a socket.

    I get the following error when I execute the send:
    at java.io.ObjectInputStream$PeekInputStream.readFull y(Unknown Source)
    at java.io.ObjectInputStream$BlockDataInputStream.rea dShort(Unknown Source)
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
    at java.io.ObjectInputStream.<init>(Unknown Source)
    at Agent.runAgent(Agent.java:125)
    at Agent.<init>(Agent.java:53)
    at Agent.main(Agent.java:193)

    The code for the class that generates the error:
    		while (runAgent) {
     
    			// At this point, we can read for input and reply with
    			// appropriate output.
    			try {
    				serverSocket = agentSocket.accept();
    				in = new ObjectInputStream(serverSocket.getInputStream());
    				out = new ObjectOutputStream(serverSocket.getOutputStream());
     
    				InetAddress addr = agentSocket.getInetAddress();
     
    				// Print out details of this connection
    				System.out.println("Accepted Client : Address - "
    						+ addr.getHostAddress().toString());
     
    				Object temp = null;
     
    				//while ((performanceProfile = (PerformanceProfile) in.readObject()) != null) {
    				while ((temp = in.readObject()) != null) {
    					if(temp instanceof PerformanceProfile){
    						performanceProfile = (PerformanceProfile) temp;
    						System.out.println("Profile received: " + performanceProfile.getName());
    					}else if(temp instanceof String){
    						String reply = "";
    						performanceProfile = null;
    						if(temp.toString().equals("profile_status")){
    							if(performanceProfile == null ){
    								reply = "no_profile";
    							}else if(!performanceProfile.isRunning()){
    								reply = "not_running";
    							}else if(performanceProfile.isRunning()){
    								reply = "running";
    							}
    						} else if(temp.toString().equals("stop_profile")){
    							stopPerformanceProfile();
    							System.out.println("Stopping performance profile");
    						}
    						out.writeObject(reply);
    					}
    					break;
    				}
     
    				if(performanceProfile != null){
    					if(!performanceProfile.isRunning()){
    						startPerformanceProfile();
    					}
    				}
     
    				//serverSocket.close();
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			} catch (ClassNotFoundException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			} 
    		}

    The code that send the object:
    String command = "profile_status";
    		String reply = "";
    		// Create new output stream to send the data in bytes
    		try {
    			socket = new Socket(agent, 11111);
    			// Instantiate the input and output variables for the sockets
    			OutputStream os = socket.getOutputStream();
    			InputStream is = socket.getInputStream();
     
    			ObjectOutputStream oos = new ObjectOutputStream(os);
    			ObjectInputStream ois = new ObjectInputStream(is);
     
    			// Write the object
    			oos.writeObject(command);
     
    			Object temp = null;
     
    			while ((temp = ois.readObject()) != null) {
    				if (temp instanceof String) {
    					reply = temp.toString();
    				}
    				break;
    			}
     
    			// oos.writeObject(command);
    			oos.flush();
    			oos.close();
    			os.flush();
    			os.close();
    			socket.close();
     
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (ClassNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    		return reply;

    TO make it complete I included the source of the Agent and the Server below.

    src-agent.zip
    src-server.zip

    I can't figure out why this error occurs and maybe somebody can help me.
    Last edited by treshr; December 9th, 2011 at 08:34 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: EOFException on sending object

    You left off the first line(s) of the error message. It would give the name of the exception and maybe some more details.
    What you did post shows that your code was creating an ObjectInputStream object at line 125 when the error occurred.

    If you want any help on this you will have to create a SSCCE that shows the problem. Your zip files contain TOO many source files.
    When I work on a client-server problem I put all the classes into a single file so all the debugging print outs are on one screen and in time sequence.
    Last edited by Norm; December 9th, 2011 at 01:25 PM.

Similar Threads

  1. java.io.EOFException when sending object through socket
    By treshr in forum Java Networking
    Replies: 2
    Last Post: November 8th, 2011, 06:13 AM
  2. [SOLVED] sending a parameter to a new JDialog
    By luisp88 in forum AWT / Java Swing
    Replies: 4
    Last Post: October 5th, 2011, 09:31 AM
  3. Sending integers through a socket
    By Fricken Hamster in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 20th, 2011, 05:44 PM
  4. Sending large Strings ?! only sending a line
    By camel in forum Java Networking
    Replies: 2
    Last Post: April 19th, 2011, 12:41 PM
  5. Sending SMS in java
    By pipi in forum What's Wrong With My Code?
    Replies: 12
    Last Post: January 26th, 2011, 08:10 PM