클라이언트에서 서버로 이미지 파일을 두 개 이상 보내고 싶습니다. 응용 프로그램에서 코드를 작성하지만 하나의 이미지 만 보내 게됩니다. 클라이언트 응용 프로그램에는 한 프레임이 있으며 서버 응용 프로그램에도 서버를 시작/중지 할 수있는 프레임이 있습니다.Java : 소켓을 사용하여 클라이언트에서 서버로 이미지 파일을 두 개 이상 보내십시오.
클라이언트 응용 프로그램에서 이미지 파일을 보내고이 이미지 파일을 서버 컴퓨터에 보내면이 이미지 파일을 열려고 할 때 아무 것도 없지만 서버 응용 프로그램 (서버 프레임)을 닫으면 문제가 하나 더 있습니다. 이미지를 볼 수 있습니다.
코드 :
클라이언트 사이트 :
public void run() {
while (true) {
try {
byte[] buffer = new byte[8192];
fis = new FileOutputStream("C:\\"+(s1++)+".jpg"); // fis is FileOutputStream
while ((count = in.read(buffer)) > 0){ //count is a integer and 'in' is InputStream
fis.write(buffer, 0, count);
fis.flush();
}
} catch (Exception e) {}
}
}
문제 : 만
- 서버 측에서
public void sendPhotoToServer(String str){ // str is image location try { InputStream input = new FileInputStream(str); byte[] buffer=new byte[1024]; int readData; while((readData=input.read(buffer))!=-1){ dos.write(buffer,0,readData); // dos is DataOutputStream } } catch (FileNotFoundException e) { } catch (IOException e) { } }
이 코드는 스레드로 실행 첫 번째 이미지는 클라이언트가 보내는 복사입니다.
- 서버 응용 프로그램을 닫을 때만이 이미지를 볼 수 있습니다.
예외가없는 나는 연속적으로 다른 클래스의 sendPhotoToServer 방법은 모든 이미지 파일을 보내 전화 :
if (photoSourcePath != null) {
clientClass.sendPhotoToServer(photoSourcePath+"\\"+rowData.get(5));
}
당신이 예외를받을 수 있나요? 그리고 어떻게'sendPhotoToServer'를 호출할까요? –
예외가 there.In 다른 자바 클래스 I이 같은 sendPhotoToServe 메소드 호출 없다 (photoSourcePath + 경우 (! photoSourcePath = NULL) { \t \t \t \t \t \t \t \t clientClass.sendPhotoToServer을 "\\"+ rowData.get (5)); \t \t \t \t –
아무 것도하지 않고 예외를 잡았으니 확실합니까? 그리고'sendPhotoToServer'를 루프에서 호출하고 있습니까? 또한 질문을 편집하여 관련 코드를 추가하고 주석에 넣지 마십시오. –