Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java getInputStream()何时返回null?_Java_Sockets - Fatal编程技术网

Java getInputStream()何时返回null?

Java getInputStream()何时返回null?,java,sockets,Java,Sockets,当我们在创建客户机之后第二次调用Socket.getInputStream()时,它返回null。我能做什么?根据无法返回null。它要么返回一个InputStream,要么抛出一个IOException 如果它抛出一个IOException,那么您要么关闭了套接字,要么另一侧关闭了套接字,要么在通信过程中出现了其他问题。根据无法返回null。它要么返回一个InputStream,要么抛出一个IOException 如果它抛出了一个IOException,那么您要么关闭了套接字,要么另一端关闭了

当我们在创建客户机之后第二次调用
Socket.getInputStream()
时,它返回null。我能做什么?

根据无法返回
null
。它要么返回一个
InputStream
,要么抛出一个
IOException

如果它抛出一个
IOException
,那么您要么关闭了套接字,要么另一侧关闭了套接字,要么在通信过程中出现了其他问题。

根据无法返回
null
。它要么返回一个
InputStream
,要么抛出一个
IOException

如果它抛出了一个
IOException
,那么您要么关闭了套接字,要么另一端关闭了套接字,要么在通信过程中出现了其他问题。

如果您无意中使用了此模式,它会感觉像是返回了空值:

InputStream is = null;
try {
   is = socket.getInputStream();
} catch (IOException e) {
  // TODO will be logged once logging is implemented...
  // e.printStackTrace();
}
is.read(); //  <-- NPE in case IOException...
InputStream=null;
试一试{
is=socket.getInputStream();
}捕获(IOE异常){
//一旦执行日志记录,TODO将被记录。。。
//e.printStackTrace();
}
is.read();// 如果您无意中使用了此模式,它会感觉像是返回了null值:

InputStream is = null;
try {
   is = socket.getInputStream();
} catch (IOException e) {
  // TODO will be logged once logging is implemented...
  // e.printStackTrace();
}
is.read(); //  <-- NPE in case IOException...
InputStream=null;
试一试{
is=socket.getInputStream();
}捕获(IOE异常){
//一旦执行日志记录,TODO将被记录。。。
//e.printStackTrace();
}
is.read()//