Implement CCS for Android push messaging on Google App Engine using python -


i trying implement ccs server side of android application on google app engine. code works fine when hosted on local computer , able send push messages device. when deploy same on gae, throws following errors

2013-08-18 06:54:55.950 / 500 11ms 0kb mozilla/5.0 (macintosh; intel mac os x 10_7_5) applewebkit/537.36 (khtml, gecko) chrome/28.0.1500.95 safari/537.36 106.197.45.136 - - [18/aug/2013:06:54:55 -0700] "get / http/1.1" 500 0 - "mozilla/5.0 (macintosh; intel mac os x 10_7_5) applewebkit/537.36 (khtml, gecko) chrome/28.0.1500.95 safari/537.36" "mad-push.appspot.com" ms=12 cpu_ms=21 app_engine_release=1.8.3 instance=00c61b117c247a73c2df78d7e42f9a5653723e54 e 2013-08-18 06:54:55.941 invalid debugflag given: socket e 2013-08-18 06:54:55.942 debug:  e 2013-08-18 06:54:55.943 debug: debug created /base/data/home/apps/s~mad-push/1.369591069415732344/xmpp/client.py e 2013-08-18 06:54:55.943 debug:  flags defined: socket e 2013-08-18 06:54:55.944 debug: socket       start plugging <xmpp.transports.tcpsocket instance @ 0x10928c88> <xmpp.client.client instance @ 0x10928c10> e 2013-08-18 06:54:55.946 debug: socket       stop  plugging <xmpp.transports.tcpsocket instance @ 0x10928c88> out of <xmpp.client.client instance @ 0x10928c10>. e 2013-08-18 06:54:55.946 client instance has no attribute 'dispatcher' traceback (most recent call last):   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__     rv = self.handle_exception(request, response, e)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__     rv = self.router.dispatch(request, response)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher     return route.handler_adapter(request, response)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__     return handler.dispatch()   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch     return self.handle_exception(e, self.app.debug)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch     return method(*args, **kwargs)   file "/base/data/home/apps/s~mad-push/1.369591069415732344/main.py", line 70, in     auth = client.auth(username, password)   file "/base/data/home/apps/s~mad-push/1.369591069415732344/xmpp/client.py", line 214, in auth     while not self.dispatcher.stream._document_attrs , self.process(1): pass attributeerror: client instance has no attribute 'dispatcher' e 2013-08-18 06:54:55.948 traceback (most recent call last):   file "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 223, in handle     result = handler(dict(self._environ), self._startresponse)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__     response = self._internal_error(e)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__     rv = self.handle_exception(request, response, e)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__     rv = self.router.dispatch(request, response)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher     return route.handler_adapter(request, response)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__     return handler.dispatch()   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch     return self.handle_exception(e, self.app.debug)   file "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch     return method(*args, **kwargs)   file "/base/data/home/apps/s~mad-push/1.369591069415732344/main.py", line 70, in     auth = client.auth(username, password)   file "/base/data/home/apps/s~mad-push/1.369591069415732344/xmpp/client.py", line 214, in auth     while not self.dispatcher.stream._document_attrs , self.process(1): pass attributeerror: client instance has no attribute 'dispatcher' 

please note application on gae contains xmpppy library folder locally. downloaded source code xmpppy.sourceforge.net/

here test code deployed in gae

import webapp2 import sys, json, random, string, xmpp server = 'gcm.googleapis.com' port = 5235 username = 'my app id' password = 'api key' registration_id = 'device registration id'  unacked_messages_quota = 1000 send_queue = []  # return random alphanumerical id def random_id():   rid = ''   x in range(8): rid += random.choice(string.ascii_letters + string.digits)   return rid  def message_callback(session, message):   global unacked_messages_quota   gcm = message.gettags('gcm')   if gcm:     gcm_json = gcm[0].getdata()     msg = json.loads(gcm_json)     if not msg.has_key('message_type'):       # acknowledge incoming message immediately.       send({'to': msg['from'],             'message_type': 'ack',             'message_id': msg['message_id']})       # queue response server.       if msg.has_key('from'):         # send dummy echo response app sent upstream message.         send_queue.append({'to': msg['from'],                            'message_id': random_id(),                            'data': {'pong': 1}})     elif msg['message_type'] == 'ack' or msg['message_type'] == 'nack':       unacked_messages_quota += 1  def send(json_dict):   template = ("<message><gcm xmlns='google:mobile:data'>{1}</gcm></message>")   client.send(xmpp.protocol.message(node=template.format(client.bind.bound[0], json.dumps(json_dict))))  def flush_queued_messages():   global unacked_messages_quota   while len(send_queue) , unacked_messages_quota > 0:     send(send_queue.pop(0))     unacked_messages_quota -= 1    class mainhandler(webapp2.requesthandler):     def get(self):         client = xmpp.client('gcm.googleapis.com', debug=['socket'])         client.connect(server=(server,port), secure=1, use_srv=false)         auth = client.auth(username, password)         if not auth:             self.response.out.write('failed')             sys.exit(1)         client.registerhandler('message', message_callback)         send_queue.append({'to': registration_id,'message_id': 'reg_id','data': {'message_destination': 'regid','message_id': random_id()}})         while true:             client.process(1)             flush_queued_messages()    app = webapp2.wsgiapplication([('/', mainhandler)],debug=true) 

as per https://developers.google.com/cloud-messaging/server#role

note google appengine not support connections xmpp (ccs).


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo