今天用socket进行编程练习时,发现程序到了getInputStream()这里就进行不下去了
Socket socket = new Socket("127.0.0.1", 800);
ObjectInputStream reader = new ObjectInputStream(socket.getInputStream());
System.out.println("a");
ObjectOutputStream writer = new ObjectOutputStream(socket.getOutputStream());
就这样的一个测试代码,a不会打印出来
后来发现是getInputStream()会一直阻塞在那里阻塞
我把两行代码调了一下就好了,还不太清楚原因,先记下来
Socket socket = new Socket("127.0.0.1", 800);
ObjectOutputStream writer = new ObjectOutputStream(socket.getOutputStream());
System.out.println("a");
ObjectInputStream reader = new ObjectInputStream(socket.getInputStream());