int c;
while((c=in.read())!=-1){
System.out.print((char)c);
out.write(c);
out.flush();
}
改成 int c = in.read();
while((c!=-1){
System.out.print((char)c);
out.write(c);
c = in.read();
System.out.println("the value is " + c);
out.flush();
}
看看是否会有c==-1的情况呢
while((c=in.read())!=-1){
System.out.print((char)c);
out.write(c);
out.flush();
}
改成 int c = in.read();
while((c!=-1){
System.out.print((char)c);
out.write(c);
c = in.read();
System.out.println("the value is " + c);
out.flush();
}
看看是否会有c==-1的情况呢
你创建的是服务器
没有人访问怎么会执行呢???
telnet yourIP 8080
然后输入东西,再看看
我考虑了好久,可能是服务器端读取字节流时c=in.read(),c永远不会等于-1
郁闷哦!!
c为什么就不能够判断流的结束呢?请高手看看哦:)
" Connection: Keep-Alive "
也就是socket连接不会有c==-1的情况要么断开连接(打印 IO Exception)
是不是这个意思啊
int c=in.read();
int count = in.available();//表示这个流的大小
while(count-- > 0){
System.out.print((char)c);
out.write(c);
c=in.read();
out.flush();
}
try{
}catch(IOException e) {
System.err.println("IO Exception");
} finally {
// Always close it:
try {
out.close();
in.close();
socket.close();
System.out.println("finally");
} catch(IOException e) {
System.err.println("Socket not closed");
}可是服务器端就是不能够判断socket.getInputStream()输入流何时结束??
服务器端读取字节流时c=in.read(),c永远不会等于-1是不是和连接方式有关?
欢迎加入讨论:)
当一个stream结束时,in.read()会返回-1,这肯定不会错的哦
我想可能时stream根本就没有结束。。你认为呢?我现在的问题是我的程序中已经结束了流啊