我正在制作一个传输文件的程序。在这个方法的过程中,我得到了书面错误:
"通过对等方重置连接:套接字写入错误"
我传输的文件大小为96MB。
(clientSocket是SSLSocket)
客户端:
Activity_1课程:
clientSocket = (SSLSocket) sslContext.getSocketFactory().createSocket();
clientSocket.connect(...);
clientSocket.setEnabledCipherSuites(clientSocket.getSupportedCipherSuites());
clientSocket.startHandshake();
Activity_2 Class:
SSLSocket clientSocket = Activity_1.clientSocket;
final DataInputStream dis = new DataInputStream(clientSocket.getInputStream());
int n = 0;
final byte[] buf = new byte[8192];
fos = new new FileOutputStream....
while ((n = dis.read(buf)) != -1) {
counter += n;
fos.write(buf, 0, n);
runOnUiThread(new Runnable() {
@Override
public void run() {
...
}
});
}
if (counter >= file_size) {
System.out.println("CLOSED");
fos.flush();
fos.close();
clientSocket.close();
}
服务器:
FileInputStream fis = new FileInputStream...
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(bis);
byte[] mybytearray = new byte[8192];
OutputStream os;
try {
os = clientSocket.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
int read = -1;
while ((read = dis.read(mybytearray)) > -1) {
dos.write(mybytearray, 0, read);
}
System.out.println("CLOSED");
dos.flush();
dos.close();
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
什么可能导致此问题发生?
先谢谢。