Nginx服务器与uwsgi,flask和sleekxmpp

时间:2018-05-23 07:41:41

标签: nginx flask xmpp uwsgi sleekxmpp

我正在尝试使用带有uwsgi,flask和sleekxmpp的nginx服务器处理一些消息。 这是代码。

system_profiler SPUSBDataType | grep -A 11 -w "iPad\|iPhone\|iPad"

我使用这些选项通过uwsgi运行代码。

import ssl, json, logging, threading, time
from flask import Flask
from sleekxmpp import ClientXMPP
from sleekxmpp.exceptions import IqError, IqTimeout

smsg = """{
        "version":1,
        "type":"request",
        "messageId":"xxyyzz",
        "payload":
        {
                "deviceType":"ctlr",
                "command":"getDeviceInfo"
        }
}"""


class XMPP(ClientXMPP):

    rosterList=[]

    def __init__(self, jid, password):
        ClientXMPP.__init__(self, jid, password)

        self.add_event_handler('session_start', self.session_start, threaded = True)
        self.add_event_handler('message', self.message, threaded=True)
        self.ssl_version = ssl.PROTOCOL_SSLv23

    def session_start(self, event):
        self.send_presence(pshow='online')

        try:
            self.rosterList.append(self.get_roster())
        except IqError as err:
            print 'Error: %' % err.iq['error']['condition']
        except IqTimeout:
            print 'Error: Request time out'

    def message(self, msg):
        data = msg['body'][12:]
        dictData = json.loads(data)
        print data
        if 'payload' in dictData.keys():
            for lists in dictData['payload']['indexes']:
                print lists
        elif 'message' in dictData.keys():
            print 'Request accepted'

app = Flask(__name__)

#logging.basicConfig(level = logging.DEBUG)
xmpp = XMPP('jid', 'password')

class XmppThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        if xmpp.connect(('server', '5222')):
            xmpp.process(block=True)

xt = XmppThread()
xt.start()

@app.route('/')
def send():
    xmpp.send_message(mto='receiver', mbody=smsg, mtype='chat')
    return '<h1>Send</h1>'

当我通过键入命令运行uwsgi时,如'/ usr / sbin / uwsgi --ini uwsgi.ini',它运行良好。我可以发送和接收消息。但是,当我在CentOS 7的服务上运行时,接收正在工作,但发送不起作用。 我需要更多选择或遗漏某些东西吗?

0 个答案:

没有答案