A bug of Jdk1.5 socket api ?

//compile and run following typical/simple Client/Server test cases with jdk1.5.

// Sever.java

public class Server {

public static void main(String[] args) {

try{

java.net.ServerSocket ss = new java.net.ServerSocket(1234);

java.net.Socket s = ss.accept() ;

java.io.InputStream is = s.getInputStream() ;

java.io.OutputStream os = s.getOutputStream() ;

java.io.ObjectInputStream ois = new java.io.ObjectInputStream (is); //line1

java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (os); //line2

System.out.println(ois.readObject());

oos.writeObject("world");

ois.close() ;

oos.close();

s.close() ;

ss.close() ;

}catch(Exception e) {

e.printStackTrace() ;

}

}

}

// Client.java

public class Client {

public static void main(String[] args) {

try{

java.net.Socket s = new java.net.Socket("localhost", 1234);

java.io.OutputStream os = s.getOutputStream() ;

java.io.InputStream is = s.getInputStream() ;

java.io.ObjectInputStream ois = new java.io.ObjectInputStream (is);//line3

java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream (os); // line4

oos.writeObject("hello") ;

oos.flush() ;

System.out.println(ois.readObject());

ois.close();

oos.close() ;

s.close() ;

}catch(Exception e){

e.printStackTrace() ;

}

}

}

1. run Server then Client, both will blocking!!

2. put line2 before line1 or put line4 before line3, it works well. it took me 4 hours finding this.

So how to explain this, is it a bug?

[1690 byte] By [yixiaoqianga] at [2007-11-26 21:40:59]
# 1
No bug! As I see it both client and server are blocked waiting for the other side to send an object! Use separate threads for the read and write then both sides so the read threads on each side can block waiting for data without the write threads being blocked.
sabre150a at 2007-7-10 3:26:02 > top of Java-index,Core,Core APIs...
# 2
At least always create the ObjectOutputStream, and flush it, before creating the ObjectInputStream for the same socket.
ejpa at 2007-7-10 3:26:02 > top of Java-index,Core,Core APIs...