UNIT 30 네트워크 전송 2 로봇 SW 콘텐츠 교육원 조용수.

Slides:



Advertisements
Similar presentations
Programming with Android: Network Operations
Advertisements

SCJP 6.0 Lecturer Kuo-Yi Chen 151, 153, 154, 155, 156, 157
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Data Structures Lecture 2 Fang Yu Department of Management Information Systems National Chengchi University Fall 2011.
Exception Handling – illustrated by Java mMIC-SFT November 2003 Anders P. Ravn Aalborg University.
IPhone/Android & MySQL Hongsheng Lu CSE40333/ Spring University of Notre Dame.
Networking.  Many applications provide & use data & services via the Internet  Android includes multiple networking support classes, e.g.,  java.net.
1 Working with Webservices Nilanjan Banerjee Mobile Systems Programming University of Arkansas Fayetteville, AR
The project Information Retrieval A.A P. Ferragina – Dipartimento di Informatica, University of Pisa –
Android App to control an IRC Bot. Background What is IRC and what does an IRC Bot do? IRC is Internet Relay Chat. It is a place that you can connect.
Cosc 4730 Brief return Sockets And HttpClient And AsyncTask.
Programming with Android: Network Operations Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Performance measurements for inter-process communication.
JSON (JavaScript Object Notation).  A lightweight data-interchange format  A subset of the object literal notation of JavaScript (or ECMA-262).  A.
HTTP and Threads. Download some code I’ve created an Android Project which gives examples of everything covered in this lecture. Download code here.here.
Arrays And ArrayLists - S. Kelly-Bootle
Web Security Programming I Building Security in from the Start Except where otherwise noted all portions of this work are Copyright (c) 2007 Google and.
Classes, Objects, Arrays, Collections and Autoboxing Dr. Andrew Wallace PhD BEng(hons) EurIng
MVC 패턴과 Spring.
UART Test UNIT 14 로봇 SW 교육원 조용수. 학습 목표 UART Init UART Send UART Receive UART -> Debugging Console Up/Down Game 제작 2.
Mobile Programming Lecture 14 Communicating via the Internet.
Recitation 1 CS0445 Data Structures Mehmud Abliz.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
Cosc 4730 Brief return Sockets And HttpClient (and with AsyncTask) DownloadManager.
로봇 모니터링 2/2 UNIT 21 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Broadcasting Service 2.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
Networking Android Club Networking AsyncTask HttpUrlConnection JSON Parser.
HTTP and Threads. Download some code I’ve created an Android Project which gives examples of everything covered in this lecture. Download code here.here.
Online Service 1. Authorization Request (Start URL) 2. Login page 3. Credentials 4. Authorization page 5. User decision 6. Authorization.
前置工作 1. 安裝 TomCat 2. 下載及安裝 AppServ exe 內含 Appache 2.2/Php5/MySQL 3. 修改相關參數檔 Appache 2.2/conf/ httpd.conf, workers.properties TomCat/conf/server.xml.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
HTTP and Threads. Getting Data from the Web Believe it or not, Android apps are able to pull data from the web. Developers can download bitmaps and text.
이경화 Ch13. 웹 프로그래밍 설계 및 실습 MVC2 Member.
로봇 모션 편집기 4/4 UNIT 25 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 에디트 텍스트를 사용할 수 있다. 아이템을 삭제할 수 있다. 아이템을 편집할 수 있다. 2.
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
Lab 2 Primer Assignment 3 Structure File I/O More parsing and HTTP Formatting.
데이터 저장 & Fragment UNIT 28 로봇 SW 콘텐츠 교육원 조용수. 데이터 저장 & Fragment SharedPreference 로 데이터 저장 Fragment 의 이해 2.
웹 프로그래밍 설계 및 실습 MVC1 Member 이경화
Server - Client Communication Getting data from server.
JSON Android Club 2015.
Java for C++ Programmers A Brief Tutorial. Overview Classes and Objects Simple Program Constructors Arrays Strings Inheritance and Interfaces Exceptions.
Mark Dixon 1 11 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
네트워크 전송 1/2 UNIT 29 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Android Network 통신 2.
MCQ Which is the correct syntax for placing the string "boat" into an ArrayList name recVehicles in position 3 (index 2) for the first time? a)recVehicles.set(3,
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
Arrays and ArrayLists Topic 6. One Dimensional Arrays Homogeneous – all of the same type Contiguous – all elements are stored sequentially in memory For.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
로봇을 조종하자 4/4 UNIT 18 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Intent Activity 호출 2.
Which Jacket? An app by Ashley Kaminski. Yet another weather app… …but this one gives you relevant data! Returns the current weather and the weather in.
로봇을 조종하자 1/5 UNIT 14 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 터치 이벤트를 처리할 수 있다. 2.
Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.
ClaRA web services V. Gyurjyan Clas12 Software Meeting
Java Programming Persistent Data Types. Persistent Data Structure A persistent data structure is a data structure having an internal state that never.
App Package Folder App data Folders Local Roaming Temp Removable Storage (SD Card) Cloud Credential Locker B/ground Transfer Publishers Shared Folder.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
MVC 패턴과 Spring.
Developing for Chromecast Cast Companion Library & Custom Receiver Application.
LIMS SOLR Integration Jake Lin Shmulevich Lab
HUJI Post PC Workshop 5 Files, Threading, and Web Services Sasha Goldshtein
Android aplikacija i baze podataka
Sockets, Routing, Sessions, Handlers
RADE new features via JAVA
CS 190 Lecture Notes: Exception Handling
CS 190 Lecture Notes: Exception Handling
CS 190 Lecture Notes: Tweeter Project
UNIT 08 그림책 만들기 2/2 로봇 SW 콘텐츠 교육원 조용수.
// Please Setting App_name to Send Successful
程式範例 - Android String url = "
Presentation transcript:

UNIT 30 네트워크 전송 2 로봇 SW 콘텐츠 교육원 조용수

학습 목표 Http Parameter 추가 JSON Object

Http 전송 방식 Http 정보 전달 방식 GET POST 주소 줄 뒤쪽으로 전달 파라메타가 연결되는 타입 전달 길이가 제한되어 , 많은 양의 데이터 전송이 어려움. 주소가 String 으로 전달되어 전달 파라메타가 노출됨. POST 포함되는 파라메타가 Body 에 포함되어 전달됨. 다량의 데이터 전송이 가능. 주소에 데이터가 노출되지 않음

HTTP GET parameter 추가 private class HttpAsyncTask extends AsyncTask<String, Integer, String> { @Override protected String doInBackground(String... params) { // TODO Auto-generated method stub BufferedReader in = null; StringBuffer sb = new StringBuffer(""); Log.d("HTTP", "Request"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); HttpClient client = new DefaultHttpClient(); /** * Http GET Examples */ nameValuePairs.add(new BasicNameValuePair("user_name", "Name")); nameValuePairs.add(new BasicNameValuePair("pass", "Password")); nameValuePairs.add(new BasicNameValuePair("user_email", "email")); String paramString = URLEncodedUtils.format(nameValuePairs, "utf-8"); if(!params[0].endsWith("?")){ params[0] += "?"; } Log.d("HTTP" , "GET URL: " + params[0] + paramString); HttpGet request = new HttpGet(params[0] + paramString); HttpResponse response = client.execute(request); …

HTTP POST parameter 추가 private class HttpAsyncTask extends AsyncTask<String, Integer, String> { @Override protected String doInBackground(String... params) { // TODO Auto-generated method stub BufferedReader in = null; StringBuffer sb = new StringBuffer(""); Log.d("HTTP", "Request"); try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); HttpClient client = new DefaultHttpClient(); /** * HTTP POST Examples */ HttpPost httppost = new HttpPost(params[0]); nameValuePairs.add(new BasicNameValuePair("user_name", "Name")); nameValuePairs.add(new BasicNameValuePair("pass", "Password")); nameValuePairs.add(new BasicNameValuePair("user_email", "email")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(httppost); … return sb.toString(); }

JSON Java Script Object Notation 경량의 Data 교환 형식 Name/value 쌍으로 되어 있으며, { } 로 데이터를 구성한다. 생성이 용이하고 , 다수의 언어에서 라이브러리를 제공하므로 쉽게 사용 가능하다. { "APP":"TEST_JSON", "USER":[ { "이름": "테스트01","나이": 25, "성별": "여"}, { "이름": "테스트02","나이": 20, "성별": "남"} ] }

JSONObject <JSONArray 클래스> Object get (int index) int getInt (int index) String getString int index) boolean getBoolean (int index) JSONArray getJSONArray (int index) JSONObject getJSONObject (int index) <JSONObject 클래스> Object get (String key) int getInt (String key) String getString (String key) boolean getBoolean (String key) JSONArray getJSONArray (String key) JSONObject getJSONObject (String key)

JSONObject // JSON Object 생성 및 값 입력 JSONObject obj = new JSONObject(); obj.put("이름","덩치"); obj.put("거주지","서울"); // key 에 해당하는 Value 추출 String data = obj.get("key"); // JSON형태의 String을 JSONobject String data = "{\"이름\":\"덩치\",\"거주지\":\"서울\"}"; JSONObject obj = new JSONObject(data);

JSON Array <example 1> String Json = "[8, 9, 6, 2, 9]"; try{ int sum = 0; JSONArray ja = new JSONArray(Json); for (int i = 0; i < ja.length(); i++){ sum += ja.getInt(i); } }catch (JSONException e){ ;}

JSONObject Array <example 2> String Json = "[ {\"Product\" : \"Mouse\", \"Maker\":\"Samsung\", \"Price\":23000}," + "{\"Product\" : \"KeyBoard\", \"Maker\":\"LG\", \"Price\":12000}," + "{\"Product\":\"HDD\", \"Maker\":\"Western Digital\", \"Price\":156000}]"; try{ String result = ""; JSONArray ja = new JSONArray(Json); for (int i = 0; i < ja.length(); i++){ JSONObject order = ja.getJSONObject(i); result += "product: " + order.getString("Product") + ", maker: " + order.getString("Maker") + ", price: " + order.getInt("Price") + "\n"; } }catch (JSONException e){ ;}

JSON Parsing private void ParseJson(String result) { try { JSONObject json = new JSONObject(result); String appName = json.getString("APP"); Log.d("TEST_JSON", "APP Name:" + appName); JSONArray nameArray = json.getJSONArray("USER"); for (int i = 0; i < nameArray.length(); i++) { JSONObject userInfo = nameArray.getJSONObject(i); Log.d("TEST_JSON", "USER Name:" + userInfo.getString("이름")); Log.d("TEST_JSON", "USER Years:" + userInfo.getInt("나이")); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace();

실습 1: Http 연결 Http Client 로 연결하기 Test.json 가져오기

User Info JSON 데이터를 저장할 Class { "APP":"TEST_JSON", "USER":[ "이름": "테스트01", "나이": 25, "성별": "여", "주소": "서울특별시 양천구 목동", "특기": ["농구", "야구"], "가족관계": {"#": 2, "아버지": "홍판서", "어머니": "춘섬"}, "회사": "경기 안양시 만안구 안양7동" } ] class User_Info { public String name; public Integer year; public String gender; public String address; public ArrayList<String> hobby; public HashMap<String, String> family; public String company;

User Info class User_Info { public String name; public Integer year; public String gender; public String address; public ArrayList<String> hobby; public HashMap<String, String> family; public String company; public User_Info() { hobby = new ArrayList<String>(); family = new HashMap<String, String>(); } public ArrayList<String> getHobby() { return hobby; public void setHobby(String hobby) { this.hobby.add(hobby); public String getFamily(String key) { return family.get(key); public void setFamily (String key, String value) { family.put(key, value); };

User Info ArrayList<User_Info> alUserInfo = new ArrayList<MainActivity.User_Info>(); private User_Info setUserInfo(JSONObject json) { User_Info user = new User_Info(); try { user.name = json.getString("이름"); user.year = json.getInt("나이"); user.gender = json.getString("성별"); user.address = json.getString("주소"); JSONArray jaHobby = json.getJSONArray("특기"); for(int i = 0; i < jaHobby.length(); i++) { user.hobby.add(jaHobby.getString(i)); } JSONObject family = json.getJSONObject("가족관계"); user.family.put("#", ""+family.getInt("#")); user.family.put("아버지", ""+family.getString("아버지")); user.family.put("어머니", ""+family.getString("어머니")); user.company = json.getString("회사"); Log.d("MainActivity", "setUserInfo " + user.toString()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); Log.d("MainActivity", "Exception!!!"); return user;

User Info Parsing private void ParseJson(String result) { try { JSONObject json = new JSONObject(result); String appName = json.getString("APP"); JSONArray nameArray = json.getJSONArray("USER"); Log.d("TEST_JSON", "APP Name:" + appName + " Length:" + nameArray.length()); for (int i = 0; i < nameArray.length(); i++) { JSONObject userInfo = nameArray.getJSONObject(i); alUserInfo.add(setUserInfo(userInfo)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace();

실습 1: Http 연결 User Info 를 ListView 로 표현