2 Attachment(s)
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:
Code :
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:
Code :
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.
Attachment 891
Attachment 892
I can't figure out why this error occurs and maybe somebody can help me.
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.