Serializability problem.

Problem : I am trying to send objects from client to server using the ObjectOutpuStream and ObjectInputStream. One object gets transferred without problem, but the application gets stuck when I try to send another(second) object. Please go through the code. I have specified where exactly the application is getting stuck. I am not getting any exceptions either.

CODE :

The client side,.. sends a string as a command, and the the Obj n strings in a fixed sequence to execute the command.

// initng streams

public ClientStub(BufferedReader in, PrintWriter out, ObjectInputStream ois, ObjectOutputStream oos)

{

//client=clientRec;

try

{

this.in=in;

this.out=out;

this.oos=oos;

this.ois=ois;

}

catch(Exception e)

{

System.out.println(e);

}

}

// some code in between n then

if (identificationCode.equals("SGLUSRADD") || identificationCode.equals("MULUSRADD"))

{

User usr = (User)objToTransfer;

oos.println(usr);

out.println(method);

String decTransfer = in.readLine();

//System.out.println("CLIENT -- decTransfer : "+decTransfer);

String tmp = in.readLine();

//System.out.println("CLIENT -- tmp : "+tmp);

if (decTransfer.equals("1"))

dec = JOptionPane.showConfirmDialog (this,"The sequence of given username already exists," +

" would you like to add further records to it starting from "+tmp);

if (decTransfer.equals("0"))

dec = JOptionPane.showConfirmDialog(this,"The sequence of given username does not exist," +

" would you like create a new sequence starting from "+tmp);

out.println(dec);

}

The server stub recieving the data

// init

public ClientWorker(Socket client1)

{

this.client=client1;

System.out.println ("Client Thread Created");

try

{

in = new BufferedReader(new InputStreamReader(client.getInputStream()));

out = new PrintWriter(client.getOutputStream (), true);

ois = new ObjectInputStream(client.getInputStream());

oos = new ObjectOutputStream(client.getOutputStream());

//System.out.println("Inside TRY for assigning IN and OUT");

}

catch(IOException e)

{

System.out.println("In or Out for particular Client Failed");

}

}

// some code

if ( line.equals("SGLUSRADD")) //SingleUserAdd

{

try

{

//ObjectInputStream oisT = new ObjectInputStream(client.getInputStream ());

System.out.println("Inside SingleUserAdd");

Object obj=ois.readObject(); // <<<<<< Problem,... 1st object comes n gets added n all,.. second time,.. it comes till here n just gets stuck man

User usr = (User)obj;

usr.setPort(in, out, ois, oos);

usr.add("Single");

System.out.println ("Single User Added");

}

catch(Exception e)

{

System.out.println("SERVER: Singleusr ClientWorker : "+e);

}

}

[3040 byte] By [akkyy21a] at [2007-10-3 5:56:14]
# 1
Create the streams once per socket at both sender and receiver.
ejpa at 2007-7-15 0:37:27 > top of Java-index,Archived Forums,Socket Programming...
# 2
I am creating them once only.
akkyy21a at 2007-7-15 0:37:27 > top of Java-index,Archived Forums,Socket Programming...
# 3
You're running multiple input streams off the same socket, and both the BufferedReader and the ObjectInputStream are buffered, so they are buffering each other's data, so they're getting confused.The same applies to the output streams.Don't do this. Find another
ejpa at 2007-7-15 0:37:27 > top of Java-index,Archived Forums,Socket Programming...
# 4
Ok, got it. So having 2 input streams on the same socket is the problem. But here I am using a TCP connection. What do you suggest to do?
akkyy21a at 2007-7-15 0:37:27 > top of Java-index,Archived Forums,Socket Programming...
# 5
ObjectInputStream.readLine(), and yes I know it's deprecated. In this situation it's really your only option.
ejpa at 2007-7-15 0:37:27 > top of Java-index,Archived Forums,Socket Programming...
# 6
ejp: couldn't he create Object array, and index it, when reading a new object, just add it to the array. He shouldn't need to use the readLine method.I can't say anything though, 10% of my code I use is old. Remeber the 'ol days of JDK 1.1?
watertownjordana at 2007-7-15 0:37:27 > top of Java-index,Archived Forums,Socket Programming...
# 7
No idea, I haven't analysed what he's using readLine() for.I've just been reviving some code I wrote in 1998.
ejpa at 2007-7-15 0:37:27 > top of Java-index,Archived Forums,Socket Programming...