마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

GCM 관련 메시징 처리 질문이요.

0 추천

안녕하세요

GCM 관련해서 http://developer.android.com/google/gcm/gs.html  링크를 봐가면서 작업을 하고 있는데

좀 난해한 부분이 있어서 질문드립니다. 구글에서 제공하는 GCM 레퍼런스 인데..

이러한 부분이 있습니다.

Sending a message

When the user clicks the app's Send button, the app sends an upstream message using the newGoogleCloudMessaging APIs. In order to receive the upstream message, your server should be connected to CCS. You can use the code shown in Writing the Server Code as a sample XMPP client to connect to CCS.

서버쪽으로 업스트림 메시지를 전송하기 위한 부분인 것 같은데요.. 그런데 바로 아래에 보면...

As described above in Step 1, the app includes a broadcast receiver for thecom.google.android.c2dm.intent.RECEIVE intent. This is the mechanism GCM uses to deliver messages. WhenonClick() calls gcm.send(), it triggers the broadcast receiver's onReceive() method, which has the responsibility of handling the GCM message. In this sample the receiver's onReceive() method calls sendNotification() to put the message into a notification:

위와 같은 설명이 있는데 대충 gcm.send 함수를 콜하면 onReceive 메소드를 호출해서 메시지를 notification 하겠다는 말인데...왜  서버에게 업스트림 메시지를 전송하기 위한 부분을 클라이언트 어플쪽 리시버에서 처리하는 지 ,,,, 

분명 CSS서버에게 upstream message를 send하면 onReceive를 호출하여 sendNotification해서 알림을 주겠다는 것인데...이 구조가 지금 어플에서 업스트림 메시지를 서버에게 전송하고 서버는 다시 앱에게 다운스트림 메시지를 전송하기 때문에 onReceive쪽에서 메시지를 받아서 처리한다는 말인가요?

긴글 죄송합니다.

시베리아수컷타이거 (560 포인트) 님이 2013년 6월 17일 질문

1개의 답변

0 추천
GCM이 이번에 업데이트 되면서 Upstream 기능도 추가가 되었습니다.

(기존 GCM Library는 DEPRECATED 되었습니다.)

우선 developer 사이트에 있는 예제에서 upstream 을 사용하는 방법을 보여준거고,

registerBackground()  함수내에 보시면 주석으로 여기서 보여주는 Demo App에서는 upstream으로 메시지를 보내고

그걸 echo로 받아서 메시지를 처리하겠다라고 써있네요..

 

그런 의미에서 위 예제는 upstream 예제 + 메시지 수신예제 가 합쳐진 예제라고 볼 수도 있습니다.

추가로 upstream을 굳이 왜 쓰냐 라고 하면 한가지 답변으로는 기존 GCM은 push를 보냈을때 이 push message를 수신자가

제대로 받았는지 확인여부가 되지 않는데, 만약 upstream 을 통해 ACK message를 보내줄 수 있다면 수신자가 제대로

push message를 받았는지의 여부를 알 수 있겠죠? 이런 용도로도 쓰실수 있다고 보시면 됩니다.
-쫑- (1,790 포인트) 님이 2013년 6월 17일 답변
...