Page 345 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 345

int indexOfContentLength = header.indexOf(CONTENT_LENGTH);
                        int valueStartPos = indexOfContentLength + CONTENT_LENGTH.length();
                        int indexOfEOL = header.indexOf('\n', indexOfContentLength);
                        String lengthValStr = header.substring(valueStartPos, indexOfEOL).trim();
                        int retValue = Integer.parseInt(lengthValStr);
                        return retValue;
                    }
                }
                // 소리 전송
                class Transmit implements Runnable {
                    byte[] buf = new byte[buffersize];
                    int count;
                    @Override
                    public void run() {
                        while (Trtigger) {
                            if ((count = targetDataLine.read(buf, 0, buf.length)) != -1) { //targetDataLined으로
             마이크로부터의 소리를 받아옴
                                try {
                                    outputStream.write(buf, 0, count); //받아온 소리를 전송
                                    outputStream.flush();
                                } catch (IOException e) {
                                    init();
                                    break;
                                }
                            }
                        }
                    }
                }
                // 소리 수신
                class Recieve implements Runnable {
                    byte[] buf = new byte[buffersize];
                    int count;
                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        while (Rtrigger) {
                            try {
                                if ((count = inputStream.read(buf, 0, buf.length)) != -1) { //소켓으로부터 소리
            를 받아옴
                                    sourceDataLine.write(buf, 0, count); //sourceDataLine으로 스피커로 소리
            전송
                                }
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }




                                                         -  338  -
   340   341   342   343   344   345   346   347   348   349   350