자바 기본 파일 전송,수신 프로그램 만들고 있는데

소켓이 계속 끊어져 ㅠㅠ


class fileThread extends Thread {

private Socket socket;

Socket socketfile;


public fileThread(Socket socketfile) {

this.socket = socketfile;

}


public void run() {

try {

DataInputStream dis = new DataInputStream(socket.getInputStream());

File file = new File("C:\\오리\\captureImage.png");

FileOutputStream fos = new FileOutputStream(file);

BufferedOutputStream bos = new BufferedOutputStream(fos);

int ch = 0;

   while ((ch =dis.read()) != -1) {

    System.out.println(ch);

bos.write(ch);

bos.flush();

//fos.close();

   }

   bos.close();

   System.out.println("bos 종료");

   fos.close();

   System.out.println("fos종료");


//socket.close();

} catch (Exception e) {

System.out.println(e.getMessage());

}

}

}

이게 서버소켓 받아서 파일 저장하는 클래스고

public class PostThread extends Thread {

File file;

OutputStream os;

Socket sock;

DataOutputStream dos;

DataInputStream dis;

peekCapture capture;

BufferedWriter bw;

BufferedReader br;

public PostThread(Socket sock) {

//capture.start();

try {

os = sock.getOutputStream();

bw = new BufferedWriter(new OutputStreamWriter(os));

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}



public void  run() {

//while(true){

try {

while(true){

sleep(5000);

dos = new DataOutputStream(sock.getOutputStream());

file = new File(

"C:\\captureImage_a.png");

System.out.println("이미지 리드");

dis = new DataInputStream(new FileInputStream(

file));

System.out.println("dis 입력");

int b = 0;

while ((b = dis.read()) != -1) {

System.out.println(b);

dos.write(b);

dos.flush();

System.out.println("사진데이터전송");

}

dis = null;

dos = null;

//s = null;

}

} catch (Exception e) {

System.out.println(e + "소켓 연결하는 부분");

}

//}

}

}

이게 파일일을 전송하는 클래스야 ㅠㅠ