我想将套接字中的输入流读入 byteArray ,但出现以下错误:
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
我不明白为什么,因为在我完成读取 inputStream 之前我不会关闭我的套接字
try {
in = connexion.getSocket().getInputStream();
out = connexion.getSocket().getOutputStream();
byte[] buffer= new byte[2048] ;
ByteArrayOutputStream baos= new ByteArrayOutputStream();
int read = 0;
while((read = in.read(buffer)) > 0) // exception thrown here
{
baos.write(buffer, 0, read);
}
reception = baos.toByteArray();
}
catch (IOException e) {
e.printStackTrace();
}
finally{
try{
in.close();
out.close();
connexion.getSocket().close();
}
catch(IOException ioException){
ioException.printStackTrace();
}
}
服务器端:
public static void main(String[] args) throws Exception {
ServerSocket s = new ServerSocket(port,2);
Socket soc ;
while(true){
soc = s.accept(); } }
非常感谢