当前位置: 技术问答>java相关
readline() 和 Forte for java 3
来源: 互联网 发布时间:2015-03-06
本文导语: 为什么我在Forte for java 中调用readline()就没有问题,但不在集成环境中使用就只能得倒一个Timeout Exception????代码是一样的!!! 下面是些蹩脚的英文: I am trouble in using readline func.Who can help me??? My code l...
为什么我在Forte for java 中调用readline()就没有问题,但不在集成环境中使用就只能得倒一个Timeout Exception????代码是一样的!!!
下面是些蹩脚的英文:
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?????
下面是些蹩脚的英文:
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?????
|
蹩脚的英文!!!