java - Determine type of serialized object -


I need to send messages (the user requests the engine and the engine responds to the user) the flow is basically a socket

  + -------- + orderly request + -------- + | Server | & Lt; ==== Networks ==== & gt; | Client | + -------- + Sorted response + -------- + ^ ^ | Request / Feedback | Mouse / keys | Object VV + -------- + -------- + | Engine | | User | + -------- + + -------- +   

Now, it only makes sense to not change the aspect again I'm working on both sides, so I'm planning to use an object like this:

  / ** * A client requests * / intangibles applying UserRequest Serializable call service request.engine callback (this); * It will tell the engine what the request is, the engine will determine its response at that time. * / Abstract Engine Response Engine Callback (engine engine); } / ** * Engine has calculated a response. * / Abstract Class Engine Response Tool Serializable {/ ** * User feedback will call. User callback (this); * It tells the user what the engine was thinking about his request, and what happened as a result. * / Abstract zero user callback (user user); }   

In my server and client sockets I am not following the following, how do I know what the subclass of request and response is coming? I see a status like

  object request = in.readObject (); // now what? How do I know what to put it? // Can I put it just like UserRequest request = (UserRequest) (in.readObject ()); Engine.addToRequestQueue (request); // should take care of the implementation details?   

My first thought was to pass everything through the strings, but Java seemed a bit silly while providing a serialization. But how do I ensure that I know which wire has come across the wire? For that matter, do I need to know, unless I only send users' servers and engineering to clients?

Simply use the provided example keyword:

  object o = in.readObject (); If (for example SomeUserRequest) o {SomeUserRequest Sur = (SomeUserRequest) o; ..} and if (o installation of second user sequence) {..}    

Comments