Networking Laboratory | - 자바 웹...

33
Client-Server Application

Transcript of Networking Laboratory | - 자바 웹...

Page 1: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Client-Server Application

Page 2: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Client 어플리케이션 개발 및 Server 연동

Local Push

Android: Started service, Bound service, Intent service

iOS: Local Notification

Push Notification

Android: Google Cloud Messaging (GCM)

iOS: Apple Push Notification Service (APNS)

Data sending and Receiving

JSON, XML

Page 3: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Android Started service 애플리케이션 컴포넌트에 의해 론칭 됨

백그라운드에서 무한정 실행됨 (자신을 시작한 것이 없어지더라도)

startService() 메소드를 이용하여 시작하며, 완료 후 stopSelf()를 호출하여 중단

Bound service Started service와 유사하나, 바운스 결과를 자신에게 반환하며 자신

을 론칭한 컴포넌트와 상호작용도 허용한다는 것이 다름

bindService() 메소드를 사용하여 시작하며, 더 이상 필요하지 않을시 unbindService() 메소드를 호출하여 멈춤

Intent service Service 클래스의 서브 클래스이며, 편의 클래스임

IntentService 클래스 사용 시 각 요청을 실행하는 onHandleIntent() 메소드만 구현하면 됨

Page 4: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

iOS: Local notification백그라운드에 있는 애플리케이션이 사용자에게 메시지 표

시를 하기 위한 로컬 알림 기능

원격 알림(Remote/Push notification) 기능과 다르며, 원격서버에 의존하지 않고 로컬 애플리케이션에서 실행 가능

UIUserNotificationSettings을 통해 알림 형태, 소리 등을 설정하며, registerUserNotificationSettings을 이용하여 사용자에게 퍼미션을 요청함

Page 5: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

iOS: Local notification로컬 알림 타입 설정 및 사용자 퍼미션 요청 코드

Page 6: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

iOS: Local notification백그라운드로 내려간 후 10초 후 알림을 위한 코드

scheduleLocalNotification으로 알림 설정

Page 7: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

iOS: Local notification

iOS 10 부터 시뮬레이터에서는 확인 되지 않음

Page 8: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

iOS: Local notification예약된 알림의 취소

scheduledLocalNotifications으로 현재 알림 목록을 얻음

cancelLocalNotification: 각각의 알림을 취소

cancelAllLocalNotifications: 예약된 모든 알림을 취소

Page 9: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Android: Google Cloud Messaging (GCM) Push Notification Server(PNS) 기반 메시지 전송 플랫폼

Uracle Push Message Center(UPMC)를 이용함

Android GCM 서버와 HTTP 프로토콜을 이용하여 서비스 구현

UPMC 3.5 이하 버전

initPushService 토큰 요청 User 등록 Service 등록 메시지 수신

UPMC 3.6 이상 버전

initPushService Service 등록 (자동 토큰 요청) User 등록 메시지 수신

Page 10: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Android: Google Cloud Messaging (GCM) DataFlow diagram

1. Register

2. Register ID

3. Service Register

4. Result Service Register

5. User Register

6. Result User Register

8. Received Message

9. Read Message

7. Send Message

7-1. Send Message

Page 11: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Service Register Sequence Diagram

1. registerPushService

2. _registerPushUser

3. sendBroadcast

4. registerPushService

5. requestData

6. receivedData7. taskCompleted

8. sendBroadcast

UIUINotification

ManagerNotification

ManagerPushManagerPushManager PushHandlerPushHandler UPNSServiceUPNSService ReceiverServiceReceiverService

NetworkManagerNetworkManager

Page 12: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

User Register Sequence Diagram

1. sendBroadcast

2. registerPushUser

3. requestData

4. receivedData5. taskCompleted

6. sendBroadcast

UIUINotification

ManagerNotification

ManagerPushManagerPushManager PushHandlerPushHandler UPNSServiceUPNSService ReceiverServiceReceiverService

NetworkManagerNetworkManager

Page 13: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Read Message Sequence Diagram

1. pushMessageReadConfirm

2. pushMessageReadConfirm

3. sendBroadcast

4. pushMessageReadConfirm

5. requestData

6. receivedData7. taskCompleted

8. sendBroadcast

UIUINotification

ManagerNotification

ManagerPushManagerPushManager PushHandlerPushHandler UPNSServiceUPNSService ReceiverServiceReceiverService

NetworkManagerNetworkManager

Page 14: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Android: Google Cloud Messaging (GCM) SDK 설정

MPushLibrary : GCM/UPNS Push 활용 라이브러리

mcore.mobile.lic : Push 라이센스 정보가 담긴 파일

Manifest.xml: Push 구동을 위한 설정이 필요한 파일

SDK 적용 방법

Project의 libs 폴더에 lib 추가

Assets/res 폴더에 라이센스 및 설정 추가

Page 15: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Android: Google Cloud Messaging (GCM) Push service 등록

Page 16: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receiver 등록

Receiver 해제

http://www.evernote.com/l/Ahg1PzprxlZHMozkXpmAVLHDrJEO-E8on40/

Page 17: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

iOS: Apple Push Notification Service (APNS) Apple에서 제공하는 영구적인 보안 채널에 공급자를 연결하

여 대상 장치에 알림을 보낼 수 있는 서비스

Apple APNS 서버와 TLS 인증으로 연결된 APNS Provider 서버를 사용

1. The app registers for push notifications (SSL 인증서 생성 및 등록)

2. The OS asks APNS for a device token

3. The app receives the device token

4. The app sends the token to provider

5. The provider sends a push notification to the APNS Server

6. APNS sends the push notification to user app

APNS는 메시지 전송 시 5. 6. 5. 6. 5. 6을 지속적으로 반복

Page 18: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

DataFlow diagram

1부터 3까지의 구체화

Page 19: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Sequence Diagram

Page 20: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Sequence Diagram

DelegateDelegate PushManagerPushManager ReceiverReceiver ProviderProvider APNSAPNS

Page 21: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

APNS Receive Sequence Diagram

DelegateDelegate PushManagerPushManager ReceiverReceiver ProviderProvider APNSAPNS

Page 22: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Registering for APNS

Page 23: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receive a token from APNS server

APNS server로부터 64bites 문자열을 받아옴

Page 24: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Provider server

APNS 메시지 전송을 위한 서버 파일 (Server: jsp 코드)

Page 25: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receive the message from APNS server

Page 26: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Sending : Android and iOS http request 사용

Form 문을 사용하여 전송

Page 27: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Sending : Android and iOS서버에서 처리 후 그 결과를 다시 전송 (Server : php)

Page 28: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Sending : Android and iOS 전송 결과를 다시 받아 처리 필요

Page 29: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receiving : Android and iOS JSON 데이터

JavaScript Object Notation (JSON)

클라이언트 브라우저 및 AJAX 사용 웹 서비스 간에 소량의 데이터를 신속히 교환할 수 있는 효율적인 데이터 인코딩 형식

Key Value 코딩 방식

Serialization(일종의 암호화) 데이터를 서버에서 전달하며, 클라이언트 즉 데이터를 수신한 Device에서는 JSON 모듈을 사용하여 Deserialization을 한 후 사용

XML 데이터

Page 30: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receiving : Android and iOS JSON 데이터

XML 데이터

HTML을 획기적으로 개선하여 만든 언어

웹에서 구조화된 문서를 전송 가능하도록 데이터에 의미를 부여하는 메타데이터를 기술할 목적으로 만든 다목적 마크업 언어

XML 파싱은 Library화 하여 사용하는 것이 일반적임

XML JSON

Page 31: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receiving : Android and iOS JSON데이터와 XML 데이터

XML JSON

장점

1. 스키마(Schema)가 있어서 데이터 무

결성 검증 용이

2. 다양한 Data type 사용 가능

3. Xpath/Xquery를 사용하면 JSON보다

파싱이 용이함

1. 내용이 함축적이며 최소한의 정보만을

담는 구조로 XML 대비 용량 적음

2. Name/value의 간단한 Syntax 구조로

markup overhead가 없음

3. Javascript에서도 쉽게 사용 가능

단점

1. JSON에 비해 복잡하고 Overhead가

존재

2. 실 데이터가 아닌 tag 글자로 데이터

양 불필요하게 증가

1. 콤마가 누락되거나 중괄호가 잘못 닫

히는 등 오염에 취약함

2. Namespace 문제가 발생하는 경우가

종종 발생함

Page 32: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receiving의 구현다량의 데이터를 한 번에 받는 경우

데이터를 받는 동안 Loading 필요

많은 이미지를 받는 경우 한 번에 Table에 넣는데 무리가 있음

데이터 일부를 받게 한 후, More를 이용하여 데이터를 추가로 받게 하는 것이 일반적임

Page 33: Networking Laboratory | - 자바 웹 프로그래밍monet.skku.edu/wp-content/uploads/2016/09/MAD_Week3_CSA.pdf · 2016-10-18 · Android: Google Cloud Messaging (GCM) Push Notification

Receiving의 실제 구현 More 구현을 위한 데이터 처리 방법

1. 처음 접속 시 1page 분량의 데이터를 서버에 요청

2. 요청한 데이터를 Device에서 받은 후 Array 형태로 데이터 저장

3. 사용자가 More 버튼을 터치하는 경우 다시 서버로 2page (다음 페이지) 데이터를 서버에 요청

4. 전송 받은 데이터를 기존 Array 데이터 뒤에 붙임

5. Table 객체는 Reload 메소드를 통해 화면을 새로 고쳐 추가데이터를 화면에 나타냄