마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 - 자바 소켓통신 간 이미지 깨짐현상입니다~

0 추천
Andorid(Client)


public void OnBtnSendImg() { // 이미지를 서버에 전송하는 함수 

            File file = new File(FileUri);


  DataInputStream dis;

  PrintWriter out = new PrintWriter(mWriter, true);

  out.println("ImgSend..");

  try {

   dis = new DataInputStream(new FileInputStream(file));

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

   byte[] buf = new byte[1024];

   while (dis.read(buf) > 0) {

    dos.write(buf);

    dos.flush();

   }

   dos.close();

  } catch (FileNotFoundException e1) {

   // TODO Auto-generated catch block

   e1.printStackTrace();

  }catch (IOException e) {

   // TODO Auto-generated catch block

   e.printStackTrace();

  }

 }

FileUri = 갤러리에서 선택한 이미지의 경로를 의미합니다~클라이언트가 파일형식으로 서버에게 데이터를 보냅니다~




Java(Server)


System.out.println("파일수신시작!!");

      File f = new File("C:\\Users\\신우\\Desktop","a.jpg");

                  FileOutputStream output = new FileOutputStream(f);

                  byte[] buf = new byte[1024];                                       

                  while(client1.getInputStream().read(buf)>0)

                  {

                     output.write(buf);

                     output.flush();

                  }

                  System.out.println("파일수신완료!!");

                  output.close();

자바 서버는 파일형식으로 데이터를 받습니다...

근데 막상데이터를 받으면 이미지가 꺠집니다..

어떤문제인지 모르겠습니다~ 도와주세요..ㅠㅠ

소켓통신을 이용하였구요~ 통신은 잘됩니다...채팅까지는 가능한데 이미지가안되요

 

dltlsdn1 (270 포인트) 님이 2015년 3월 26일 질문

1개의 답변

0 추천
dos.write(buf);

한번에 buf가 모두 전송될 거라는 환상을 버리세요.
익명사용자 님이 2015년 3월 26일 답변
리턴이 void인데 다 안보내지기도 하나요? 신기하네요 .
그리고 다른관점에서는 read 한만큼 write를 해야 하지 않을까요..
buf가 모두 전송 되지않는것이 문제인가요??
buf를모두전송하려면어떤방법이잇나요?
...