Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use "readline" in java????

Status
Not open for further replies.

gxlzlu

Programmer
Oct 8, 2001
8
CN
I am trouble in using readline func.Who can help me???
My code like this:
////////////////////////////////////////////////////////
InetAddress addr=InetAddress.getLocalHost();
System.out.println("Prepare to new socket");
clientSocket=new Socket(addr,port);
System.out.println("Past the init socket");
clientSocket.setSoTimeout(5000);
in=new BufferedReader(
new InputStreamReader(
clientSocket.getInputStream()));
out=new PrintWriter(clientSocket.getOutputStream(), true );
/////////////
//I read socket by this code:
while(in.ready()){
info=info+in.readLine()+"\n";
}
/////////////////////////////////////////////////////////

There is not any problem when I use them in Forte for java 3. But every time I used it out of Forte the system told me that "Read time out". But I used in.ready() to test, the func in.ready() return "true". I use the other way to read.The code is below:

///////////////////////////////////////////////////////
String info;
char[] ch=new char[100];
in.read(ch);
info=new String(ch);
index=info.indexOf("\n");
System.out.print("n is ");
System.out.println(index);
index=info.indexOf("\r");
System.out.print("r is ");
System.out.println(index);
System.out.println(info);
/////////////////////////////////////////////////////////

By this way I found there are something in the buffer including the char '\n' and '\r'. But why the readline func give me the Timeout Exception out of Forte?????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top