Androidクライアント用のファイルをアップロードするJavaサーバーがあります。アップロードは行いますが、完了すると、次のようにスローし続けます。
Error::java.net.SocketException: Socket is closed
コードをよく検索しましたが、何も見つかりませんでした。ファイルをアップロードしてからスローしているので、最後からforループでコードの最後に問題があると思いますが、何も問題はありません。アイデアはありますか?
class ClientThread extends Thread {
// the socket where to listen/talk
String Type;
Socket socket;
ObjectInputStream sInput;
ObjectOutputStream sOutput;
// my unique id (easier for deconnection)
int id;
// Constructore
ClientThread(Socket socket) throws InterruptedException {
// a unique id
id = ++uniqueId;
this.socket = socket;
/* Creating both Data Stream */
System.out.println("Thread trying to create Object Input/Output Streams");
while (!jobdone) {
try {
// create output first
sOutput = new ObjectOutputStream(socket.getOutputStream());
sInput = new ObjectInputStream(socket.getInputStream());
// read the username
OutputStream os = socket.getOutputStream();
FileInputStream fis = null;
DataOutputStream dos = new DataOutputStream(os);
String Request = (String) sInput.readObject();
System.out.println(Request);
String[] todoname = Request.split("\\@reza-hp");
String name = todoname[0];
System.out.println("Connecting...");
File fil = new File("D://Users//ProfileImages//reza");
System.out.println(fil);
File[] Files = fil.listFiles();
System.out.println(Files);
for (int count = 0; count < Files.length; count++) {
System.out.println(Files[count].getName());
}
os = socket.getOutputStream();
dos = new DataOutputStream(os);
dos.writeInt(Files.length);
for (int count = 0; count < Files.length; count++) {
dos.writeUTF(Files[count].getName());
}
for (int count = 0; count < Files.length; count++) {
int filesize = (int) Files[count].length();
dos.writeInt(filesize);
}
for (int count = 0; count < Files.length; count++) {
int filesize = (int) Files[count].length();
byte[] buffer = new byte[filesize];
fis = new FileInputStream(Files[count].toString());
BufferedInputStream bis = new BufferedInputStream(fis);
// Sending file name and file size to the server
bis.read(buffer, 0, buffer.length); // This line is
// important
dos.write(buffer, 0, buffer.length);
dos.flush();
fis.close();
}
dos.close();
os.close();
} catch (Exception e) {
System.out.println("Error::" + e);
}
}
Thread.sleep(5000);
Server.shutdown();
}
}
あなたのソケットは反対側から閉じられています
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加