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?????
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?????