hi,
Using the following code I am sending a query to a server socket using a PrintWriter.println function and retrieve a vector object (results).
Client Code
public Vector getDBResultSet(String query) throws ClientException, IOException{
Object obj = new Object();
if (socket != null)
{
try{
System.out.println("Sending "+query+" to Server");
writer.println(query);
try{
ois = new ObjectInputStream(input);
while ((obj = ois.readObject()) != null)
obj = ois.readObject();
}catch (EOFException eofx){
System.out.println("EOF @ object input stream!");
}
finally{
ois.close();
}
return (Vector)obj;
}catch(Exception e){
e.printStackTrace();
throw new ClientException("<html>Error: <br>"+e.toString()+"#"+e.getMessage()+"</html>");
}finally{
//writer.close();
}
}else throw new ClientException("no connection!");
}
Server side code
public void communicate()
{
try{
while (true){
String q = reader.readLine();
Vector vec = db.getResults(q);
oos = new ObjectOutputStream(output);
oos.writeObject(vec);
oos.flush();
oos.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
First time everything goes OK.
Second time
on the Client-Side I get strange errors like "ClassCastException Java.lang.Object" and if I comment out the "while" line I get a "socket closed" error...
any ideas what is wrong with it?