java.net.SocketException:sendto失败:当我尝试在WebSocket中发送文件时出现EconReset(由对等方重置连接)错误
任何人都可以帮助我解决此错误java.net.SocketException:sendto失败:当我尝试在WebSocket中发送文件时出现EconReset(由对等方重置连接)错误,java,android,sockets,websocket,Java,Android,Sockets,Websocket,任何人都可以帮助我解决此错误java.net.SocketException:sendto失败:ECONNRESET(由对等方重置连接) 我的代码 我试图发送apk文件或其他任何东西,但他拒绝发送有时发送此错误或什么也没有发生 private void sendFile(InputStream inputStream, OutputStream outputStream, String filename) throws IOException { String statusLi
java.net.SocketException:sendto失败:ECONNRESET(由对等方重置连接)
我的代码
我试图发送apk文件或其他任何东西,但他拒绝发送有时发送此错误或什么也没有发生
private void sendFile(InputStream inputStream, OutputStream outputStream, String filename) throws IOException {
String statusLine = "HTTP/1.1 200 OK" + "\r\n";
String serverdetails = "Server: Java HTTPServer";
String contentLengthLine,contentTypeLine = "";
if(filename.endsWith(".apk")) {
contentTypeLine = "Content-type: application/vnd.android.package-archive\r\n";
}
Log.d("available", String.valueOf(inputStream.available()));
contentLengthLine = "Content-Length: " + (Long.MAX_VALUE-Integer.MAX_VALUE) + "\r\n";
outputStream.write(statusLine.getBytes());
outputStream.write(serverdetails.getBytes());
outputStream.write(contentTypeLine.getBytes());
outputStream.write(contentLengthLine.getBytes());
outputStream.write("Connection: close\r\n".getBytes());
outputStream.write("\r\n".getBytes());
byte[] b = new byte[1024];
int count;
while ((count = inputStream.read(b)) >0) {
outputStream.write(b);
}
Log.d("second","done");
inputStream.close();
outputStream.flush();
outputStream.close();
}
该错误消息通常表示套接字的远程端关闭了连接,或者您与远程端之间存在网络问题。我尝试在chrome上使用它,但当我尝试在移动浏览器中使用它时,它会像那样崩溃,我发送mime类型为apk chrome read mime类型为Document的文件可能是扩展名阻止了它?还是杀毒?它还可能表明远程程序崩溃,套接字被重置。