• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem comes in BufferedReader's readLine() method in Socket

 
Natesh Mosale
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are behind the proxy..we are able to connect to
yahoo and recive messages thru telnet. Part of my java code for receiving email messages thru proxy is as follows.
Socket sock=new Socket("192.1.2.124", 23);
System.out.println("Socket "+sock);
out=new DataOutputStream(sock.getOutputStream());
in=new BufferedReader(new InputStreamReader sock.getInputStream()));
out.writeBytes("telnet 192.1.2.124 110\n");
out.writeBytes("user natesh\r\n");
//+OK Password required for user id.
line=in.readLine();//PROBLEM COMES HERE..NOT ABLE TO READ FROM INPUTSTREAM OF SOCKET
System.out.println(line);
out.writeBytes("pass ********\r\n");
//firewall telnet proxy (Version 3.2) ready:
line=in.readLine();
System.out.println(line);
out.writeBytes("telnet "+keyValue[2]+" 110\n");
System.out.println("writing ok");
The problem is if I run the my java application, the readLine method of inputstream is not working and held up. After the
output stream's writeBytes method, the readLine method
is not executing(or it is not moving to the next statement).So I couldn't get the result from my java application.
Regards
Natesh MS
 
Ryan Langley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Does the line that your program is receiving from the socket end with '\r', '\n', or "\r\n"? The readline() method, according to the javadoc, will "read a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed." Try seeing if you can read one character at a time, instead of one line at a time. Since it's a password, it whouldn't be extremely long. Just a suggestion, anyway. Hope this helps to lead you to a solution!

------------------
Cheers,
RL
 
netharam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have a method sock.setSoTimeout(milliseconds).if the timeout is set then all read operations of that socket wil raise an exception when the timeout has reached.handle the exception in your own way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!