Ejabberd Custom IQ处理程序:在收到自定义IQ节后断开用户连接。 Ejabberd 15.07

时间:2016-05-11 16:18:46

标签: erlang xmpp ejabberd

我是Erlang-Ejabberd开发的初学者,我想在Ejabberd 15.07之上创建一个模块。所以我在许多帖子和一些教程中都有一些代码作为示例开始开发我自己的模块。现在我推出了这个代码来开始。

var iq = $iq( {type: 'get', id : 'id123', from : 'renato@localhost'}).c('query', {xmlns : 'jabber:iq:seen'});
connection.sendIQ(iq, onResult);

所以在这里,使用Strophe.js我发送一个带有此功能的自定义IQ节。

<iq type="get" id="id123" from="renato@localhost" xmlns="jabber:client">
  <query xmlns="jabber:iq:seen" >
</iq>

它出现了像这样的Stanza。

2016-05-11 17:47:28.965 [info]<0.486.0>@ejabberd_listener:accept:299      (#Port<0.3939>) Accepted connection 127.0.0.1:49120 -> 127.0.0.1:5280
2016-05-11 17:47:28.966 [info]<0.507.0>@ejabberd_http:init:157 started: {gen_tcp,#Port<0.3939>}
2016-05-11 17:47:29.511 [info]<0.509.0>@ejabberd_c2s:wait_for_sasl_response:932  ({socket_state,ejabberd_http_bind,{http_bind,<0.508.0>, {{127,0,0,1},49120}},ejabberd_http_bind}) Accepted authentication for renato  by undefined from 127.0.0.1
2016-05-11 17:47:30.150 [info]<0.509.0>@ejabberd_c2s:wait_for_session:1120  ({socket_state,ejabberd_http_bind,{http_bind,<0.508.0>, {{127,0,0,1},49120}},ejabberd_http_bind}) Opened session for  renato@localhost/32685205291462981649937971
2016-05-11 17:47:31.451 [info]<0.486.0>@ejabberd_listener:accept:299 (#Port<0.3948>) Accepted connection 127.0.0.1:49122 -> 127.0.0.1:5280
2016-05-11 17:47:31.452 [info]<0.511.0>@ejabberd_http:init:157 started: {gen_tcp,#Port<0.3948>}
2016-05-11 17:47:31.453 [info]<0.390.0>@mod_test2:process_sm_iq:45   Processing IQ Get query:
{iq,<<"id123">>,get,<<"jabber:iq:seen">>,<<>>,{xmlel,<<"query">>, [{<<"xmlns">>,<<"jabber:iq:seen">>},{<<"querytype">>,<<"seen">>}],[]}}    
2016-05-11 17:49:01.556 [info]<0.508.0>@ejabberd_http_bind:handle_info:522 Session timeout. Closing the   HTTP bind session: <<"1199a026fb06de7e7c728425587b09a0b9c81433">>
2016-05-11 17:49:01.556 [info]<0.509.0>@ejabberd_c2s:terminate:1842  ({socket_state,ejabberd_http_bind,{http_bind,<0.508.0>,  {{127,0,0,1},49120}},ejabberd_http_bind}) Close session for   renato@localhost/32685205291462981649937971

然后我断开连接并且没有按预期从服务器获得结果。这就是我在日志文件中得到的内容。

erlc -DNO_EXT_LIB -I  lib/ejabberd-15.07/include -pz lib/ejabberd-15.07/lib  mod_test.erl

我正在运行ejabberd 15.07。我安装了run包并使用这些命令编译了模块。

 # -*- coding: utf-8 -*-

import sys
from mastermind import *
from PyQt5 import QtWidgets
import random
import time



class Menu_mm(QtWidgets.QDialog):
    def __init__(self,parent=None):
        QtWidgets.QWidget.__init__(self,parent)
        self.ui = Ui_MasterMind()
        self.ui.setupUi(self)

        self.ui.comboBox.addItem("Facil")
        self.ui.comboBox.addItem("Dificil")
        self.ui.comboBox.addItem("Legendario")
        self.ui.comboBox.activated.connect(self.num)
        self.ui.pushButton.clicked.connect(self.Empezar)
        self.ui.label_14.setVisible(False)
        self.ui.label_19.setVisible(False)
        self.ui.label_20.setVisible(False)
        self.ui.label_15.setVisible(False)
        self.ui.label_16.setVisible(False)



    def num(self):
        x= self.ui.comboBox.currentText()

        if x == "Facil":
             self.ui.label_6.setText("3")
             y=1
        elif x == "Dificil":
             self.ui.label_6.setText("4")
             y=2
        else:
             self.ui.label_6.setText("5")
             y=3

    def Empezar(self):
        x = self.ui.comboBox.currentText()

        if x == "Facil":
            y = 1
        elif x == "Dificil":
            y = 2
        else:
            y = 3

        continuar = 1

        while continuar == 1:


            if y == 1:
                cant_digitos = 3
            elif y == 2:
                cant_digitos = 4
            elif y == 3:
                cant_digitos = 5
            print(cant_digitos)

            #print("cant_digitos")

            digitos = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
            codigo = ''

            for i in range(cant_digitos):
                elegido = random.choice(digitos)
                while elegido in codigo:
                    elegido = random.choice(digitos)
                codigo = codigo + elegido
            print(codigo)

            global propuesta
            propuesta = self.ui.lineEdit_2.text()


            intentos = 1


            while propuesta != codigo:
                intentos = intentos + 1
                aciertos = 0
                coincidencias = 0
                for i in range(cant_digitos):
                    if propuesta[i] == codigo[i]:
                        aciertos = aciertos + 1
                    elif propuesta[i] in codigo:
                        coincidencias = coincidencias + 1



                propuesta=self.ui.lineEdit_2.text()

                self.ui.lineEdit_2.returnPressed.connect(self.checkText)


                print(propuesta)
                self.ui.label_13.setText(str(propuesta))
                self.ui.label_9.setText(str(aciertos))
                self.ui.label_11.setText(str(coincidencias))

            self.ui.label_14.setVisible(True)
            self.ui.label_15.setVisible(True)
            self.ui.label_16.setVisible(True)



    def checkText(self):
        propuesta =self.ui.lineEdit_2.Text()
        print("si")
        self.ui.lineEdit_2.clear()


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    myapp = Menu_mm()
    myapp.show()
    sys.exit(app.exec_())

之后,我将文件复制到ebin /目录,然后我启动了ejabberd服务器,其他一切正常。有人可以帮助我解释我需要什么,并告诉我是否必须更改代码,配置文件或使用更新版本。我使用这个版本好几个月了。感谢...

0 个答案:

没有答案