(I know this can be done in RMI, but I need to do this using sockets since I found there could be some setup process if RMI methods used)
Please have a look at the simple Client-Server code at http://www.coderanch.com/t/205325/sockets/java/send-any-java-Object-through
In this program, the order two objects sent by SimpleServer are known by SimpleClient.
i.e: Server
oos.writeObject(new testobject(1,"object from client"));
oos.writeObject(new String("another object from the client"));
Client does the casting according to the order the object is received.But I want to avoid this nature and make client send any object at any time so the server should also be able to handle each object sent accordingly and return a result.
testobject to = (testobject)ois.readObject();
System.out.println(to.id);}
System.out.println((String)ois.readObject());
Is there a way to "label" the objects being sent so that the action can be determined by a simple "if" statement in Server?
OR
is there a better way to use a ResultSet returned by the Server instead of my object serializing approach?
thanks in advance.
Thanks
getClass()or useinstanceofon them and handle them according to that.new String("another object from the client")its almost always pointless.