Trying to understand the data flow in Java | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Trying to understand the data flow in Java

hi, I have been working on a project using s scheme client-server, I already create my class "server" and my class "client". I have these three lines: 1) Socket s=new Socket("127.0.0.1",5432); 2) ObjectInputStream in=new ObjectInputStream(s.getInputStream()); 3) ObjectOutStream out=new ObjectOutputStream(s.getOutputStream()); The rare thing starts when the compiler gets to the second line and the program gets stuck, it doesn't carry on. BUT when I change the order like this: 1) Socket s=new Socket("127.0.0.1",5432); 2) ObjectOutStream out=new ObjectOutputStream(s.getOutputStream()); 3) ObjectInputStream in=new ObjectInputStream(s.getInputStream()); The program continues executing and does what it has to do SO my question is: why is important to write the output first and then the input? otherwise, it will get stuck

24th May 2018, 2:22 AM
Raul Oliva
Raul Oliva - avatar
1 ответ
0
Thank u very much, now I get it
24th May 2018, 1:34 PM
Raul Oliva
Raul Oliva - avatar