I am trying to connect to the POP server through Sockets in Java. I did the following code to run a LIST command to list all the emails from the server. But I don't know why on the second readLine() to read the second line and onwards, my application hangs at there.
popSock = new Socket(mailHost, pop_PORT);
inn = popSock.getInputStream();
outt = popSock.getOutputStream();
in = new BufferedReader(new InputStreamReader(inn));
out = new PrintWriter(new OutputStreamWriter(outt), true);
//USER and PASS commands to auth the server are ok
out.println("LIST");
String response = in.readLine();
System.out.println(response);
//Attempt to read the second line from the buffer but it hangs at here.
response = in.readLine();
System.out.println(response);
On the second in.readLine()
, the application gets stuck at here and doesn't proceed from here. When I run the LIST
command on telnet, I get the whole list of emails. So I should get the same response from the socket but I am not. How should I read the whole response line by line from the server?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…