2011-01-06 194 views
0

嘿伙计们, 我发送邮件到应用程序引擎的xmpp客户端时,似乎无法使用xmpppy客户端。 我没有收到任何错误。消息只是没有到达那里。 从应用引擎的客户端发送消息到sl4a客户端的作品。 发送消息往返于Google Talk的客户端以及从sl4a客户端发送消息也同样适用。Python xmpppy客户端不发送消息到appengine xmpp客户端

任何帮助将不胜感激。

这里是Python代码

import xmpp 
import time 

_SERVER = 'talk.google.com', 5223 
commandByXMPP() 

def commandByXMPP(): 
    global xmppUsername 
    xmppUsername = '[email protected]' 
    global xmppPassword 
    xmppPassword = 'obscured' 
    global xmppClient 
    global operator 
    operator = "[email protected]" 

    jid = xmpp.protocol.JID(xmppUsername) 
    xmppClient = xmpp.Client(jid.getDomain(), debug=[]) 
    xmppClient.connect(server=_SERVER) 
    try: 
    xmppClient.RegisterHandler('message', XMPP_message_cb) 
    except: 
    exitCellbot('XMPP error. You sure the phone has an internet connection?') 
    if not xmppClient: 
    exitCellbot('XMPP Connection failed!') 
    return 
    auth = xmppClient.auth(jid.getNode(), xmppPassword, 'botty') 
    if not auth: 
    exitCellbot('XMPP Authentication failed!') 
    return 
    xmppClient.sendInitPresence() 
    print "XMPP username for the robot is:\n" + xmppUsername 

    start=time.time() 
    i=0 
    try: 
    outputToOperator("starting") 
    while time.time()-start<15: 
     print "tick" 
     xmppClient.Process(1) 
     i = i +1 
     if i % 10 == 0: 
     outputToOperator("hello") 
    outputToOperator("exiting") 
    except KeyboardInterrupt: 
    pass 


def XMPP_message_cb(session, message): 
    jid = xmpp.protocol.JID(message.getFrom()) 
    global operator 
    command = message.getBody() 
    print command 

def outputToOperator(msg): 
    print "Outputting "+msg+" to " + operator 
    xmppClient.send(xmpp.Message(operator, msg)) 

回答

4

1)检查[email protected]是在名册上[email protected]。 GTalk不会传递来自未知用户的消息。 2)发送型的聊天的信息:

xmppClient.send(xmpp.Message(operator, msg, typ='chat')) 

一些客户端不能很好地反应,以接收“正常”的消息,这不具有type属性。

+0

谢谢乔。我一直在试图追捕这件事大约一周。非常感谢你,先生。 – Garrows 2011-01-07 09:45:13