pythondjangoxmppgoogle-cloud-messagingxmpppy

Referring a currently open XMPP connection from another python script present inside a django server


My application server's requirements are as follows:

  1. Receive sensor data from mobile phones (using HTTP)
  2. Process them (python libraries)
  3. Send notification to the mobile devices (rendered as notifications on Android devices)

Implementation Setup:

In order to do the above, my server has three modules:

GCM App Server Module: I have implemented GCM Message App Server using CCS that talks to the Google's servers (that sits between the app server and Android devices) for delivering messages to/from mobile devices running Android. Following is from their official website (previous link):

The GCM Cloud Connection Server (CCS) is an XMPP endpoint that provides a persistent, asynchronous, bidirectional connection to Google servers. The connection can be used to send and receive messages between your server and your users' GCM-connected devices.

In the documentation, they have given a sample python script that I have referred and used to implement my GCM App server. This implementation is executed as a standalone script that runs forever.

Python Inference Library and Django app module: I have implemented the inference library in python that processes sensor data received from the phones. It has a Django interface to talk to the Android devices. The inference library resides inside the Django app server.

PROBLEM:

The GCM App Server script contains a few functions, one of them being send_message(), that sends messages to the Android devices. I need to refer this function in my inference library scripts when some processed data is available to be sent to the devices. Or I need to refer to the persistent open XMPP connection client to send messages. I want to avoid putting the processing code in the GCM app server script. I have been stuck for weeks to find a way to do the above.

Is there a way to do this with my current setup or do I need to add some other layer/module?

Any help or suggestions would be greatly appreciated.

Thanks.


Solution

  • Is there a way to do this with my current setup?

    Yes! Using multiprocessing. See answer of this question - Accessing python class variable defined inside the main module of a script