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?

