2011-01-06 196 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