Hello!
I' m creating a Java Client/Server program, so I'm trying to send a object(User) from Client to Server, then, in the server-side, I want to know what kind of object it is and then I want to save it to use that in the future..
When I try to create userReceived...then nothing happens...like..
It's possible to read the obj only once, in this case in the conditional "if" but my purpose is to know before what kind of obj is and then work with it..but of course I need to know the type of data because in the future I want to send different types of data.
Thanks in advance for your help.
What I have tried:
Client-side
<pre lang="Java">InetAddress addr = InetAddress.getLocalHost();
ObjectOutputStream oos = null;
Socket socket = new Socket(addr.getHostName(), port);
oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(user);
Server-side
server = new ServerSocket(port);
Socket mySocket = server.accept();
ObjectInputStream ois = new ObjectInputStream(mySocket.getInputStream());
if ( ois.readObject() instanceof User) {
System.out.println("Client connected!");
User userReceived = (User) ois.readObject();