Page 211 - 3-2
P. 211

super.onCreate();
                    Thread myThread = new Thread(this);
                    Log.d(this.getClass().getName(), "Thread1");
                    myThread.start();
                    Log.d(this.getClass().getName(), "Thread2");
                }


                @Override
                public IBinder onBind(Intent intent) {
                    // TODO: Return the communication channel to the service.
                    throw new UnsupportedOperationException("Not yet implemented");
                }


                @Override
                public void run(){
                    while (true) {
                        StringBuilder jsonHtml = new StringBuilder();
                        Vector<ListItem> listItem = new Vector<ListItem>();
                        try {
                            URL url = new URL("http://192.168.0.81/mdp.php");
                            //  연결 url  설정
                            //  커넥션 객체 생성
                            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                            //  연결되었으면.
                            Log.d(this.getClass().getName(), "url  접근");
                            if (conn != null) {
                                Log.d(this.getClass().getName(), "1 접근");
                                conn.setUseCaches(false);
                                //  연결되었음 코드가 리턴되면.
                                Log.d(this.getClass().getName(), "2 접근");
                                if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                                    Log.d(this.getClass().getName(), "3 접근");
                                    BufferedReader br = new BufferedReader(new
                                       InputStreamReader(conn.getInputStream(), "UTF-8"));
                                    Log.d(this.getClass().getName(), "4 접근");
                                    for (; ; ) {
                                        //  웹상에 보여지는 텍스트를 라인단위로 읽어 저장.
                                        Log.d(this.getClass().getName(), "5 접근");
                                        String line = br.readLine();
                                        Log.d(this.getClass().getName(), "6 접근");
                                        if (line == null) break;
                                        //  저장된 텍스트 라인을 jsonHtml        에 붙여넣음
                                        Log.d(this.getClass().getName(), "7 접근");
                                        jsonHtml.append(line + "\n");
                                        Log.d(this.getClass().getName(), " 연결 완료");


                                                         - 211 -
   206   207   208   209   210   211   212   213   214   215   216