>> Edit article
이름
제목
패스워드
서버에 클라이언트가 접속을 하면 곧바로 클라이언트에게 메세지 연속으로 몇개를 보냅니다.그리고 클라이언트는 그것을 받아서 출력을 합니다. 서버는 보낼때 BufferedOutputStream 이것을 이용하고 클라이언트는 받을때 BufferedInputStream 을 이용합니다. 근데 문제는 서버가 여러개를 한번에 보내면 클라이언트가 그것을 따로따로 받는게 아니라 한번에 받아버립니다. 이문제를 어떻게 해결해야 합니까? out과in은 각각 위에서 말한 io객체입니다. 서버소스 일부분 ////////////////////////////////////////////////////////////////////// public void sendMsg() { try { String msg="This is a test"; for(int i=0;i<5;i++) { out.write(msg.getBytes()); out.flush(); System.out.println("SEND : "+msg); } }catch(Exception ex) { } } ///////////////////////////////////////////////////////////////////// 클라이언트 소스 일부분 ///////////////////////////////////////////////////////////////////// public void getMsg() { byte[] recvbuf=new byte[1024]; int count; try { while (true) { Arrays.fill(recvbuf,(byte)0); if ((count=in.read(recvbuf))==-1) { break; } String recv_msg=new String(recvbuf); System.out.println("GET : "+recv_msg); } }catch(Exception ex) { } } /////////////////////////////////////////////////////////////////////--Plus and Minus
Copyleft
1999-2026 by
JSBoard Open Project
Theme Designed by
IDOO
All right reserved